F12 or Ctrl+Shift+I (Windows) / Cmd+Option+I (Mac) to open browser developer tools and access the Console tab!
Define the content and layout
Handle changes and updates
<!DOCTYPE html>
<html>
<head>
<script>
function showMessage() {
document.getElementById('demo').innerHTML = 'Hello from JavaScript!';
}
</script>
</head>
<body>
<h1 id="demo">Original Text</h1>
<button onclick="showMessage()">Click Me</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 id="demo">Original Text</h1>
<button onclick="showMessage()">Click Me</button>
<script>
function showMessage() {
document.getElementById('demo').innerHTML = 'Hello from JavaScript!';
}
</script>
</body>
</html>
HTML file:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 id="demo">Original Text</h1>
<button onclick="showMessage()">Click Me</button>
<script src="script.js"></script>
</body>
</html>
script.js file:
function showMessage() {
document.getElementById('demo').innerHTML = 'Hello from JavaScript!';
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 id="demo">Original Text</h1>
<button onclick="document.getElementById('demo').innerHTML = 'Hello from JavaScript!'">Click Me</button>
</body>
</html>
; - Explicit terminator// comment
/* comment */
var keyword (older style)let keyword (modern, recommended)const for constantsmyVar ≠ myvarif, for, etc.)number - integers and floats (3.14, 42)string - text ("hello", 'world')boolean - true/falseundefined - not assignedobject - complex datatypeof operator tells you the data type of any variable!
Number()parseInt()
String().toString()
Boolean()
+ - * / % ++ --> >= < <==== (strict) vs == (loose)&& (AND) || (OR) ! (NOT)=== and !== instead of == and !=if, else if, elseswitch statementwhile loopfor loopbreak and continue
function functionName(param1, param2) {
// code here
return result;
}
function keyword to definereturn to send back resultsnum1 and num2 with any numbers you likeconsole.log() to show each result with a labelSum: 15Difference: 5Product: 50Division: 2
age with any numberif, else if, and else statements<, >=, etc.
createGreetingname and agereturn keyword to send back your message, and use + to combine strings!