<!-- Stan Smith
Project 3
Feb 6, 2021 -->
<!DOCTYPE html>
<html lang="en">
....
Answer: The first line of the HTML page should be<!DOCTYPE html>Source code comments or other code should go after that. Here is what the beginning of the HTML file should look like:
<!DOCTYPE html>
<!-- Stan Smith
Project 3
May 1, 2026 -->
<html lang="en">
+ == = ++ < ** += . * && Answer: . ++ ** * + < == && = +=Look at the W3Schools Operator Precedence Table
var a = ["apple", "peach", "cherry", "orange", "lemon", "pear"]; a.splice(1, 3, "carrot", "celery"]; // Answer: ["apple", "carrot", "celery", "lemon", "pear"]
abs cos max min pow sin sqrt // Answer: document.writeln(Math.abs(-34.72) + " " + Math.abs(84.38) + "<br>"); document.writeln(Math.sin(0) + "<br>"); document.writeln(Math.sqrt(2)); // Output: 34.72 84.38 0 1.41421356237309505
function greeting( ) {
return "Hello, World.";
}
// is written in arrow notation as
var greeting = ( ) => "Hello, World.";
function convert( ) {
var input1 = document.getElementById("tf1");
var cm = parseFloat(input1.value) * 2.54;
var output1 = document.getElementById("para1");
output1.innerHTML = `Length in cm: ${output1}`);
}
// Answer:
var convert = ( ) => {
var input1 = document.getElementById("tf1");
var cm = parseFloat(input1.value) * 2.54;
var output1 = document.getElementById("para1");
output1.innerHTML = `Length in cm: ${output1}`);
}
Then pass this function to this JS statement as an anonymous function:
button1.addEventListener("click", convert);
Answer:
button1.addEventListener("click", ( ) => {
var input1 = document.getElementById("tf1");
var cm = parseFloat(input1.value) * 2.54;
var output1 = document.getElementById("para1");
output1.innerHTML = `Length in cm: ${output1}`);
});
<button id="btn">Click Me</button>You can also use this input tag:
<input type="button" id="btn" value="Click Me">Then use this script.js file:
function changeColor( ) {
var bodyObject = document.getElementById("b");
bodyObject.style.backgroundColor = "red";
}
function init( ) {
document.getElementById("btn").
addEventListener("click", changeColor);
}
window.addEventListener("load", init);
The preceding lines can be written using anonymous methods for
init and changeColor:
window.addEventListener("load", ( ) => {
var bodyObject = document.getElementById("btn");
bodyObject.addEventListener("click", ( ) => {
document.getElementById("btn")
.bodyObject.style.backgroundColor = "red";
});
});
var clock = { hr: 23;
min: 59;
sec: 59;
tick: function( ) {
this.sec;
if (this.sec == 60) {
this.min++;
this.sec = 0;
}
if (this.min == 60) {
this.hr++;
this.min = 0;
}
if (this.hr == 60) {
this.hr = 0;
}
toString: function( ) {
return `${hr} ${hr} ${hr}`;
}
document.writeln(clock + "<br>");
clock.tick( );
document.writeln(clock + "<br>");
var s = "abc";
var t = new String("abc");
To see this, run these JavaScript statements in a script:
var s = "abc";
var t = new String("abc");
document.writeln((typeof s) + " " + (typeof t));
// Output: string object
'use strict';
<input> <button> <textarea> <select> <option> <output>HTML Tags Listed Alphabetically (W3Schools)
id class hidden style disabled tabindex dragable required autofocusHTML Global Attributes (W3Schools)
<input> type (button checkbox radio hidden number password
color date email file image month range reset
search submit tel text time url week)
value (text)
checked (checkbox, radio)
max (number)
maxlength (number)
minlength (number)
pattern (text)
placeholder (text)
readonly
size (number)
step (number)
<button> type (button reset submit)
<textarea> cols (number)
rows (number)
readonly
maxlength (number)
placeholder (text)
wrap (hard soft)
<select> multiple
size (number)
<option> value (text)
selected
Tag Attibutes Listed Alphabetically (W3Schools)blur change click dblclick focus keydown keypress keyup load mousedown mouseenter mouseleave mousemove mouseup
HTML Events (W3Schools)