Question 2In a short paragraph, explain in your own words how webpages use HTML, CSS and Javascript together to form a website.What is the role of each?HTML provides the basic structure of sites,...






Question 2





In a short paragraph, explain in your own words how webpages use HTML, CSS and Javascript together to form a website.





What is the role of each?

HTML provides the basic structure of sites, which is enhanced and modified by other technologies like CSS and JavaScript. CSS is used to control presentation, formatting, and layout. JavaScript is used to control the behavior of different elements





Question 3





Create a function called calculateNewPrice(bool, value) that will either increase or decrease a price by a percentage if the boolean is true or false.





For example, calculateNewPrice(true, 10) will increase a price by 10 percent, and calculateNewPrice(false, 10) will decrease a price by 10 percent.





Return the value as a decimal value.





function acalculateNewPrice(bool, value){


var modulus1;


if (bool==true){


modulus1=1+value/100;


}


if (bool==false){


modulus1=1-value/100;


}


return modulus1;

}

console.log(acalculateNewPrice(true, 10))

Question 4





Create a closure function called createAccumulator(value) that will increase a value by 10 each time and multiply by 2.

function createAccumulator(value){


return function () {


return (value + 10) * 2;


};


}




let add5 = createAccumulator(5);


let add9 = createAccumulator(9);




console.log(add5(5));


console.log(add9(9));









Question 6





function updateScore(currentScore, value, bonus) {


return bonus ? currentScore + value * bonus : currentScore + value;

}





updateScore(10, 3);

updateScore(10, 3);

updateScore(10, 3, 2);









In your own words, explain how optional arguments can be used within a function, and what the ternary operator is doing in this example.





1. The actual parameters in the function cannot be more than the formal parameters, otherwise an error will be reported.

2. The index number of the actual parameter in the function is absolutely the same.

3. The meaning expressed by the ternary operator in this example is: whether the bonus is true, if it is true, it returns the value of currentScore + value * bonus, otherwise it returns the value of currentScore + value.





Question 7





Based on today's date, what would the library function Date.prototype.getDay() return?





Hint: It is a number value













Question 8





Create a function called randomBetween(x, y) that will return a random number between two numbers that are passed as parameters, x and y. Using the Math library, round the number. Add a bonus to the function and modify it so it returns a random number between the half of x, and the half of y.

unction randomBetween (x,y){


var mmax,mmin,pptr,bonus;


if (x>y){mmax=x,mmin=y};


if (y>x){mmax=y,mmin=x};


pptr=Math.random()*(mmax-mmin) + mmin;


pptr=parseInt(pptr)


bonus=Math.random ()*(parseInt(mmax/2)-parseInt(mmin/2))+parseInt(mmin/2);


bonus=parseInt(bonus)


return bonus;

}


console.log(randomBetween (5,60))





Question 9





Function that returns the number of matches found for the number greater than the sum of the first two arguments in the remaining arguments: findMatches(66, 100, 345, 2334, 66, 67, 66) should return 1. Add a bonus part of your function that will modify the function to check for the number of matches found for the number greater than the sum of the first three arguments.





:

function calculate (num, x) {


var result;


if (num == 1){


result =Math.sqrt(x);


}






if (num == 2){


result = x*x;


}


if(num == 3){


result = x/2;


}


return Math.round(result);


};




console.log(calculate(1, 100)) ;





Question 10





function updateScore(currentScore, value, bonus) {


return bonus ? currentScore + value * bonus : currentScore + value;

}













updateScore(10, 3);

updateScore(10, 3);

updateScore(10, 3, 2);









11.In your own words, explain how optional arguments can be used within a function, and what the ternary operator is doing in this example.





Create a function called calculator(num, x) that will perform a squareRoot(x), squared(x) or a dividedBy2(x) function based on number is passed as a parameter.





If num is:





1 - will perform a squareRoot(x)





2 - will perform a squared(x)





3 - will perform a dividedBy2(x)





x should be the number that calculator will operate on.





Round each number using the Math library.





function calculate (num, x) {


var result;


if (num == 1){


result =Math.sqrt(x);


}






if (num == 2){


result = x*x;


}


if(num == 3){


result = x/2;


}


return Math.round(result);


};




console.log(calculate(1, 100)) ;
Oct 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here