Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6.4.1: Loops. Write a do-while loop that counts up from userNum to 6. Ex: For us

ID: 3911067 • Letter: 6

Question

6.4.1: Loops.

Write a do-while loop that counts up from userNum to 6. Ex: For userNum = 3, output is: 3 4 5 6

var userNum = 3;

/* Your solution goes here */

-------------------------------------------------------------------------------------------------------------------------------

6.5.1: Functions.

Assign a variable solveEquation with a function expression that has three parameters (x, y, and z) and returns the result of evaluating the expression 2 * x * y + z.

/* Your solution goes here */

solveEquation(2, 4, 5.5);

-------------------------------------------------------------------------------------------------------------------------------

6.6.1: Arrays.

Loop through the array displaying the values in order.

var friendsList = [ "Ann", "Bob", "Joe", "Ron" ];

/* Your solution goes here */

-------------------------------------------------------------------------------------------------------------------------------

6.8.1: Strings.

Find the index of the string "noisy" and assign substringIndex with the index. Then, update wiseProverb replacing "noisy" with "squeaky".

var wiseProverb = "The noisy wheel gets the grease.";
var substringIndex = 0;

/* Your solution goes here */

-------------------------------------------------------------------------------------------------------------------------------

6.8.2: Using Date methods.

Display the date when Facebook's website launched in M/YYYY format. Ex: The 31st of January 1970 should be displayed as: "1/1970".

var interestingEvents = {
"Long distance telegraph": new Date(1844, 4, 24),
"First telephone call": new Date(1876, 2, 10),
"Microsoft founded": new Date(1975, 3, 4),
"World wide web born": new Date(1989, 2, 1),
"Google founded": new Date(1998, 8, 4),
"Facebook website launch": new Date(2004, 1, 4)
};
var interestingDate = interestingEvents["Facebook website launch"];

/* Your solution goes here */

Explanation / Answer

6.4.1

var userNum = 3;

do {

//for printing in browser output

document.writeln(userNum);

// for printing in console

console.log(userNum);

userNum++;

} while (userNum <= 6);

6.5.1

solveEquation(2, 4, 5.5);

function solveEquation(x, y, z) {

return 2 * x * y + z;

}

6.6.1

var friendsList = ["Ann", "Bob", "Joe", "Ron"];

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

console.log(friendsList[i]);

//or

document.write(friendsList[i]);

}

6.8.1

var wiseProverb = "The noisy wheel gets the grease.";

var substringIndex = 0;

substringIndex = wiseProverb.indexOf("noisy");

wiseProverb.replace("noisy", "squeaky");

6.8.2

var interestingEvents = {

"Long distance telegraph": new Date(1844, 4, 24),

"First telephone call": new Date(1876, 2, 10),

"Microsoft founded": new Date(1975, 3, 4),

"World wide web born": new Date(1989, 2, 1),

"Google founded": new Date(1998, 8, 4),

"Facebook website launch": new Date(2004, 1, 4)

};

var interestingDate = interestingEvents["Facebook website launch"];

document.write(interestingDate.getMonth() + "/" + interestingDate.getFullYear());