Question: Write a function declaration called countPositive that takes three String arguments: one, two, three. Convert these values to Numbers then count the number of positive

Write a function declaration called countPositive that takes three String arguments: one, two, three. Convert these values to Numbers then count the number of positive values you have. Return this count as a Number.

Calling countPositive(-10, 256, .3) should return the Number 2

Question 2 (5 Marks):

Write a function expression called onlyNegatives that takes three String arguments: one, two, three. Create a sentence (string) of only the negative values and their count. Use your countPositive() function from question 1 to figure out the count.

Calling onlyNegatives(-10, -20, 30) should return the String: There are 2 negative numbers: -10, -20.

Question 3 (5 Marks)

Simulate flipping a coin using Math.random(). Your flip() function should allow the caller to specify any number of flips, but default to 1 if none is given: flip() assumes you want to flip a coin once, where flip(3) would do it 3 times.

The function should return the number of heads and tails as a string in the following form: Heads: 1, Tails: 3

Question 4 (5 Marks)

Write a function, logBeyondThreshold, that accepts a threshold (i.e., a max value) followed by any number of arguments and logs all arguments that are larger than the threshold value to the console. Calling logBeyondThreshold(1000, 1605, 233, 2556, 256, 0) would log 1605 and 2566 to the console, since they are both larger than the threshold value of 1000. Calling logBeyondThreshold(10, 2, 3, 4) would log nothing.

Question 5 (3 Marks)

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

function createCounter() {

let count = 10;

return function(value) {

count += value;

return count;

};

}

let count = 1;

let counter = createCounter();

console.log(counter(1), counter(2), counter(3));

// What will this print and why? How does it work?

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!