JavaScript is one of the 3 languages all web developers must learn: 1. HTML to define the content of web pages 2. CSS to specify the layout of web pages 3. JavaScript to program the behavior of web pages JS can change content .innerHTML = "
Hi there
" ////// https://www.w3schools.com/js/js_conventions.asp camelCase for defining variables & functions is recommended don't start with numbers in variable & function names! math operators: + - * / GLUE :) concatenate data parts with + if you have text (String) pieces or text and number pieces combined let mySentence = 5000 + " cars are on the highway."; console.log(mySentence) //will output: 5000 cars are on the highway. let x = 5 let y = 15 let result = x + 5 * (y / x) console.log("My result is: " + result) IN THE BROWSER CONSOLE: Shift + Enter gives you multiple lines to add code /* Timer functions / methods */ // setTimeout fires once after a delay of n milliseconds setTimeput(function() { //do stuff alert() }, 3000); // a delay of 3 seconds //setInterval fires repeatedly after n milliseconds setInterval(function() { console.log("5 seconds have just passed :)"); }, 5000); // this will log the text every 5 seconds... /* Conditionals */ // if else etc... // example with boolean data type (true of false) let A = true; if(A == true) { alert("A does exist") } else{ alert("A is false") } // Comparision operators == means: equals != means: not equals // example if(A != true) > means: greater than // example if(B > 0) {alert("success"); } > means: smaller than // example if(B < 0) {alert("error"); } >= means: greater than and equal to <= means: smaller than and equal to // example if(B >= 3) { alert ("B is at least 3 or greater"); } //// chained up Conditionals if(A == true) { alert('success'); } else if(A == false) { alert('nope'); } else { alert('ERROR'); } ///SHORT version if (A == B) alert("yay") // Boolean specific (true | false) if(A) alert("yay") // means if(A == true) ... if(!A) alert("NAY") //means if(A != true) ... // Short hand version.1 (A == true) ? alert("YAY") : alert("Nay") version.2 (A) ? alert("YAY") : alert("Nay") //// Stricter comparison operators === means: is equal to and of the same data type !== means: is not equal to and of the same data type etc. // Logical operators && means: And || means: Or