-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
18 lines (16 loc) · 818 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// reference html elements
const form = document.getElementById('form');
const numOneInput = document.getElementById('num1');
const numTwoInput = document.getElementById('num2');
const resultText = document.getElementById('result');
// form event listener
form.addEventListener('submit', function(e) {
e.preventDefault();
// we can convert the strings into numbers using the Number() function
const numOneVal = Number(numOneInput.value);
const numTwoVal = Number(numTwoInput.value);
console.log(`numOneVal is of type: ${typeof numOneVal}, with a value of ${numOneVal}`);
console.log(`numTwoVal is of type: ${typeof numTwoVal}, with a value of ${numTwoVal}`);
// now the numbers add up correctly
resultText.innerText = `${numOneVal} + ${numTwoVal} = ${numOneVal + numTwoVal}`;
})