Question: Question 1 (5 Marks): Write a function declaration called sumStrings that takes three String arguments: one, two, three. Convert these values to Numbers, add them

Question 1 (5 Marks):

Write a function declaration called sumStrings that takes three String arguments: one, two, three. Convert these values to Numbers, add them together, and return the result as a Number.

Calling sumStrings(1, 2, 3) should return the Number 6

Question 2 (5 Marks):

Write a function expression called sumStringsEquation that takes three String arguments: one, two,three. Create a string equation of these values and their sum, using your sumStrings() function from question 1.

Calling sumStringsEquation(1, 2, 3) should return the String 1 + 2 + 3 = 6

Question 3 (5 Marks)

Simulate rolling a dice using Math.random(). Your roll function should allow the caller to specify any number of sides, but default to 6 if no side count is given: roll() assumes a 6 sided dice, returning a random number between 0 and 5, while roll(50) uses a 50 sided dice, and returns a random number between 0 and 49.

Question 4 (5 Marks)

Write a function, logOutsideByteRange, that accepts any number of arguments and logs all arguments larger than 255 (i.e., all numbers larger than a byte) to the console. Calling logOutsideByteRange(1, 5, 233, 255, 256, 0) would log 256 to the console, while logOutsideByteRange(1, 2, 3, 4, 255) would log nothing.

Question 5 (3 Marks)

Explain the following code in your own words, discussing how it uses JavaScript scope and closures.

function createFn(factor) {

return function(value) {

return value * factor;

};

}

let fn = createFn(10);

console.log(fn(6)); // What will this print and why?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!