* ** *** **** ***** ****** *******Use a prompt box to enter the number of rows.
1 2 3 Fizz 4 5 Buzz 6 Fizz 7 8 9 Fizz 10 Buzz 11 12 Fizz 13 15 Fizz Buzz 16 17 ...
document.writeln(convert(1.0)); // Output: 3'3"
// ExpressionInterpolation Example var name = "Larry"; var amt = "347.81"; document.writeln(`${name} owes me $${amt}.`); // Output: Larry owes me $347.81.
var output = ftInt + "\' " + inInt + "\"";to
var output = `${ftInt}\' ${inInt}\"`;
5 == 5, "5" == "5", 5 == "5", 0 == false, 1 == trueall return true.
document.writeln(`${5 == 5} ${5 == 3} ${"5" == "5"}<br>`); // The string "5" is converted to a number before // performing the comparison: document.writeln(`${5 == "5"}`); // Output: true false true true
document.writeln(`${0 == false} ${5 == true} ${0.00000001 == false}`); // Output: true false false
document.writeln(`${"1" == true} ${"" == false}<br>`); document.writeln(`${"0" == false} ${"1" == true} ${"5" == true}<br>`); document.writeln(`${"0.00" == false} ${"1.00" == true} ${"5.00" == true}`); // Output: true true false true true false true true false
document.writeln(`${5 === "5"}<br>`); document.writeln(`${"" === false} ${"1" === true}<br>`); document.writeln(`${"0" === false} ${"1" === true}<br>`); document.writeln(`${"0.00" === false} ${"1.00" === true}`); // Output false false false false false false false
var n = 1.0 - 0.8; var m = 0.3 - 0.1; document.writeln((n == m) + " "); // Output: falseWhy? Because of differing roundoff errors due to the binary representation of the double precision floating point numbers, 1.0 - 0.8 and 0.3 - 0.1 are not represented with exactly the same values. To see this, look at the output of this statement:
document.writeln((n - m)); // Output: -2.7755575615628914e-17Instead of checking for equality with floating point values, we should check that n and m are very close to each other:
document.writeln((Math.abs(n - m) < 1.0e15) + " "); // Output: true
var a = [2, 3, 5, 7, 11, 13]; document.writeln(a + "<br>"); document.writeln(a[4]); // Output: 2,3,5,7,11,13 11
a0 = 2; a1 = 3; a2 = 5; a3 = 7; a4 = 11; a5 = 13;
for(var i = 0; i < 5; i++) { document.write(a[i] + " "); } // Output: 2 3 5 7 11 13or
for(var n of a)) { document.write(n + " "); } // Output: 2 3 5 7 11 13
var a = [45.3, 'apple', false, null];
var a = [2, 3, 5, 7]; document.writeln(typeof a); // Output: object // Reason: an array is not a primitive datatype, it // is a composite datatype called an object type.
document.writeln(typeof [2, 3, 5, 7]);an array is an object.
height vertical jump weight age yearsInPros name jerseyNumber team positionBasketball Player Methods that were suggested in class:
shoot pass dribble rebound run block screen stop
var a = [2, 3, 5, 7];the properties and methods of a are accessed by the dot operator (.).
document.writeln(a.length); // Output: 4
document.writeln(a.reverse( )); // Output: [7, 5, 3, 2]
toString concat pop push shift unshiftAnswer: Check out this W3Schools reference to array methods:
var a = [2, 3, 5, 7]; var b = [9, 8, 7, 6]; // When printing the array object a, toString // is automatically called document.writeln(a.toString( ) + " " + a + "<br>"); // Output: 2,3,5,7 2,3,5,7 // The concat method concatenates two arrays. document.writeln(a.concat(b) + "<br>"); // Output: 2,3,5,7,9,8,7,6 // The pop method pops the element off // of the top (right) of the array. a.pop( ); document.writeln(a + "<br>"); // Output 2,3,5 // The push method pushes a new element // (in this case 99) onto the top of the array. a.push(99); document.writeln(a + "<br>"); // Output: 2,3,5,99 // The shift method is similar to pop, but // but the bottom (left) element is removed. a.shift( ); document.writeln(a + "<br>"); // Output: 3,5,99 // The unshift method is like push, but the new element // is added to the bottom (left) of the array. a.unshift(98); document.writeln(a + "<br>"); // Output: 98,3,5,99
at indexOf repeat toUpperCase trimUse the W3Schools String reference to help you:
document.write(Boolean(5) + " "); document.write(Boolean(283764) + " "); document.write(Boolean(0) + " "); document.write(Boolean(-203) + "<br>"); document.write(Boolean(3.14159265) + " "); document.write(Boolean(-284.378) + " "); document.write(Boolean(0.000000001) + " "); document.write(Boolean(0.0) + "<br>"); document.write(Boolean("grapefruit") + " "); document.write(Boolean("$%&*@") + " "); document.write(Boolean("0") + " "); document.write(Boolean("false") + " "); document.write(Boolean(" ") + " "); document.write(Boolean("") + "<br>"); document.write(Boolean(null) + " "); document.write(Boolean(undefined) + " "); document.write(Boolean(Infinity) + " "); document.write(Boolean(NaN) + "<br>");Then run it to check if your prediction is correct.
var n = 45; var p; if (n) { v = "nonzero"; } else { v = "zero"; } document.writeln("Value: " + v);