Created
February 27, 2024 00:42
-
-
Save vharsh/d53046f06fd6ea3a6599b2e0b87b3e7c to your computer and use it in GitHub Desktop.
DOM playground
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Calculator</title> | |
<script> | |
function execute() { | |
console.log('some DOM event triggered this function call'); | |
console.log('triggered via xxx'); | |
// 1. fetch the values | |
let x = document.getElementById("one")?.value; | |
let y = document.getElementById("two")?.value; | |
try { | |
// 2. Compute the result | |
let a = Number(x); | |
let b = Number(y); | |
document.getElementById('result').innerHTML = a + b; | |
} catch(e) { | |
console.log("TODO: why isn't a TypeError thrown during a failed casting operation?") | |
console.log(e); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<input id="one" onchange="execute()"/> | |
<p> + </p> | |
<input id="two" onchange="execute()"/> | |
<!-- <button onclick="execute()"> Submit </button> --> | |
<p id="result"></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment