<input type="text" value="Larry" placeholder="Enter name:" style="border-radius: 15px; width: 150px; height: 15px;">
<input type="button" value="Push Me">Show how to create this button with a <button> element.
<button> Push Me </button>The advantage of using the button tag is that HTML markup can be included, for example:
<button> <strong>Push Me</strong> </button>
replace replaceAll toUpperCase padStart trimUse the W3Schools documentation if needed
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script> var s = "mississippi"; document.writeln(s.replace("s", "*") + " " + "<br>"); // Output: mi*sissippi document.writeln(s.replaceAll("s", "*") + "<br>"); // Output: mi**i**ippi document.writeln(s.toUpperCase( ) + "<br>"); // Output: mississippi var b = "459"; document.writeln(b.padStart(5, "0") + "<br>"); // Output: 00459 var c = " This is a test. document.writeln("!" + c.trim( ) + "!<br>"); // Output: !This is a test.! </script> </head> <body></body> </html>
var a = "abc", b = 128.73, c = 45; var f = `###${a} %%%${b} ***${c}`; Answer: ###abc %%%128.73 ***45
someObject.someMethod( ); someFunction( );Technical Answer: A function that is actually called from the global object window like this:
window.someFunction( );When the global object window is omitted, it is understood, so someFunction( ) and window.someFunction( ) have the same effect.
isFinite isNaN parseFloat parseIntWe can use this script to test them:
document.writeln(isFinite(34544.5484)); // Output: true document.writeln(window.isFinite(34544.5484)); // Output: true document.writeln(Number.MAX_VALUE); // Output: 1.7976931348623157e+308 document.writeln(isFinite(1.0e309) + " "); // Output: false document.writeln(isNaN(0 / 0)); // Output: true document.writeln(parseFloat("453.45")); // Output: 453.45 document.writeln(parseInt("453"); // Output: 453
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 < 6; 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.
name jerseyNumber height weight position isRookieBasketball Player Methods that were suggested in class:
shoot dunk pass dribble run 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