Created
January 4, 2022 08:09
-
-
Save RanjanSushant/7f443669f374d22a31ce36799c2f98df to your computer and use it in GitHub Desktop.
TypeScript Demo code
This file contains hidden or 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
// DOM Elements | |
const addBtn = document.getElementById("add-btn"); | |
const number1 = document.getElementById("num1")! as HTMLInputElement; | |
const number2 = document.getElementById("num2")! as HTMLInputElement; | |
// function to add two numbers and return the result | |
function addNum(num1:number, num2:number): number { | |
return num1 + num2; | |
} | |
// event listener for add button | |
addBtn.addEventListener("click", function() { | |
console.log(addNum(parseInt(number1.value), parseInt(number2.value))) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment