COMP 105: HW #4

You are welcome to discuss these questions with your classmates, the instructor, or a TA. However, if you make use of any outside information in answering these questions, or if you receive help from anyone, you need to acknowledge that along with your answer.
1. What is wrong with the following function? It is supposed to find and return the value of the largest integer in an array of integers. (There may be more than one problem with this function. Describe all errors that you find. Also, the errors are all logic errors - all of the statements are legal JavaScript.)
```
function returnLargest(array)
{
var largest = array[0];
for (var i = 0; i< array.length; i++)
{
if (largest > array[i])
{
largest = i;
}
}
}
```
2. How many times will the statement `doSomething();` be executed in the following loop?
```for (var i = 0; i < 6; i = i + 2)
for (var j = 0; j <= 4; j++)
doSomething(); //count how many times this line is executed.
```
3. How many different numbers can be represented with 13 binary digits? How many different numbers can be represented with 3 hexadecimal digits?
4. How is the decimal number 63 represented in
• binary?
```0100001101010011001100010011000000110101