Javascript

Review Questions:

____ 1. What is a valid statement for declaring and initializing a variable named length to a starting value of 120?

Burdette, p3

____ 2. After the statements that follow are executed, what are the contents of firstName and fullName?

var firstName = "Ray", lastName = "Harris";

var fullName = lastName;

fullName += ", ";

fullName += firstName;

Burdette pp 32-33

____ 3. After the if statement that follows is executed, what will the value of discountAmount be?

var discountAmount;

var orderTotal = 200;

if (orderTotal > 200) {

discountAmount = orderTotal * .3;

} else if (orderTotal > 100) {

discountAmount = orderTotal * .2;

} else {

discountAmount = orderTotal * .1;

}

Burdette, pp 11, 12

____ 4. If totalMonths has a string value of “13”, what does the if statement that follows display?

var totalMonths = "13";

var years = parseInt ( totalMonths / 12 );

var months = totalMonths % 12;

if ( years == 0 ) {

alert ( months + " months.");

} else if ( months == 0 ) {

alert ( years + " years");

} else {

alert ( years + " years, and " + months + " months.");

}

Burdette, pp 27, 28

____ 5. What will futureValue contain after the for loop has been executed one time?

var years = 10;

var annualRate = 10;

var futureValue = 1000;

annualRate = annualRate / 100;

for ( i = 1; i <= years; i++ ) {

futureValue += futureValue * annualRate;

}

Burdette, pp 10, 11

____ 6. After the statement that follows is executed, rateText represents:

var rateText = document.getElementById("rate");

Burdette, p 139

____ 7. After the statements that follow are executed, guest contains:

var guest = "Ray Harris";

var quest = guest.substr(0,3).toUpperCase();

Burdette, pp 33, 34

Code example 3-1

var add = function( x, y ) {

return ( x + y );

}

alert( add (5, 3) );

____ 8. (Refer to code example 3-1) The function in this example accepts and returns?

Burdette, pp 60-65

____ 9. (Refer to code example 3-1) The alert method in this example displays?

Burdette, pp 60-65

____ 10. When you test an application with Firebug and a breakpoint is reached, you can view the current data by

Firebug is discussed a couple of times in Burdette. He doesn’t say how to do this, but you need to know, and should have seen in class.

____ 11. When you test an application with Firebug and a breakpoint is reached, you can click what to continue debugging?

Firebug is discussed a couple of times in Burdette. He doesn’t say how to do this, but you need to know, and should have seen in class.

____ 12. The code that follows has a bug in it because the second use of the variable named salesTax is spelled with all lowercase letters (salestax).

var calculateTax = function (subtotal, taxRate) {

var salesTax = subtotal * taxRate;

salestax = parseFloat(salesTax.toFixed(2));

return salesTax;

}

Assuming that there are no other problems, what will happen when the calculateTax function

is executed?

Burdette, p 28

____ 13. What will the value of the totalsString variable be after the following code is executed?

var totals = [141.95, 212.95, 411, 10.95];

totals[2] = 312.95;

var totalsString = "";

for (var i = 0; i < totals.length; i++) {

totalsString += totals[i] + "|";

}

Burdette, p 32, 33

____ 14. Given the following lines of code, what will be displayed in successive dialog boxes?

var answers = [ "C", "B", "D", "A" ];

delete answers[3];

for ( var i in answers ) {

alert (answers[i]);

}

Burdette, p 85

____ 15. Given the code that follows, what will the alert statement display?

var names = ["Mike", "Anne", "Joel"];

names.push("Ray", "Pren");

var removedName = names.pop();

alert (names.toString());

Burdette, pp 50, 51