A Pen by Obiagba Mary Ifeoma on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body id="container"> | |
<div id="displayBlock"></div> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//Named function | |
function sameFunction() { | |
let displayBox = document.getElementById('displayBox'); | |
let num3 = 3; | |
let num4 = 4; | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//Anonymous function stored in a variable | |
let sameFunction = function () { | |
let displayBox = document.getElementById('displayBox'); | |
let num3 = 3; | |
let num4 = 4; | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//Named function with parameters | |
function sameFunction(num3, num4) { | |
let displayBox = document.getElementById('displayBox'); | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} | |
sameFunction(3, 4); | |
//output: 3 + 4 = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//Anonymous function with parameters | |
let sameFunction = function(num3, num4) { | |
let displayBox = document.getElementById('displayBox'); | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} | |
sameFunction(3, 4); | |
//output: 3 + 4 = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//arrow function | |
let sameFunction = () => { | |
let displayBox = document.getElementById('displayBox'); | |
let num3 = 3; | |
let num4 = 4; | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
//arrow function with parameters | |
let sameFunction = (num3, num4) => { | |
let displayBox = document.getElementById('displayBox'); | |
displayBox.innerHTML = `${num3} + ${num4} = ${num3+num4}`; | |
} | |
sameFunction(3, 4); | |
//output: 3 + 4 = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function changeBackground(color) { | |
let container = document.getElementById('container'); | |
container.style.backgroundColor = color; | |
} | |
let redBtn = document.getElementById('redBtn'); | |
redBtn.onclick = function () { | |
changeBackground('red'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body id="container"> | |
<!-- | |
<div id="displayBlock"></div> | |
--> | |
<button id="redBtn">Red</button> | |
<button id="blueBtn">Blue</button> | |
<button id="yellowBtn">Yellow</button> |
OlderNewer