






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Answers are highlighted in blue color.
Evaluate each of the following Javascript expressions and show the value.
Convert these binary numbers into decimal numbers.
Convert these decimal values into binary numbers.
Write javascript code to do the following.
var n2 = prompt("Please enter another number."); alert("The product of "+n1+" and "+n2+" is "+ n1*n2);
// Solution 2: Put the test inside the loop. while (true) { var n = prompt("Please enter a number in the range 0…100"); if (n>=0 && n<=100) break; alert(n +" is out of range. Try again."); }
sum = sum + i; // Add i to the running sum. alert("The sum of 0 through "+max+" is "+sum);
var x =5; var y =1;
while (x > 0){ x = x-1; y = y*x; alert(x + " " + y); }
var i;
var count =0; for (i =0; i < 11; i++){ if (i < 3 || 7 <i){ count++; alert(count + " i " + i + " range 1"); }else if (i == 5){ count++; alert(count + " i " + i + " range 2"); } if ( 2<= i && i < 7){ count++; alert(count + " i " + i + " range 3"); } }
1 1 1 2 1 3 1 4 2 2 2 3 2 4 3 3 3 4 4 4
var count=0; for (var half=0; half<=2; half++) { for (var qtr=0; qtr<=4; qtr++) { for (var dime=0; dime<=10; dime++) { for (var nick=0; nick<=20; nick++) { for (penny=0; penny<=100; penny++) { if (50half + 25qtr + 10dime + 5nick + penny == 100) { count++; } } } } } } alert(count); It counts and displays the number of different way to make $1.00 using half dollars, quarters, dimes, nickels, and pennies. It tests 349,965 different combinations to find the 292 combinations that add up to exactly $1.00.