Answer the question
In order to leave comments, you need to log in
How to do it in JS?
Hello. I am a very beginner js developer and I immediately want to put everything into practice. Please tell me how to properly arrange such a very simple thing: I enter numbers into two different inputs, save them to variables, and my JS should sum them up and output them to the console. I have this code:
<div class="wrapper">
<input id="first">
<input id="second">
<button id="to_sum"></button>
</div>
(function() {
'use strict';
var value_1 = document.getElementById('first');
var value_2 = document.getElementById('second');
var sum_button = document.getElementById('to_sum');
sum_button.onclick = function(){
console.log(value_1 + value_2);
};
})();
Answer the question
In order to leave comments, you need to log in
You did not store the value of inputs in variables, but links to these elements in the DOM. Must be added to getElementById().value. Well, or value_1.value
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question