L
L
learn_to_alive2015-10-20 22:37:14
JavaScript
learn_to_alive, 2015-10-20 22:37:14

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);
  };

 
})();

But in the end it outputs to the console: [object HTMLInputElement][object HTMLInputElement].
I understand that this is an absolute elementary thing, but I want to start at least somewhere. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2015-10-20
@learn_to_alive

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 question

Ask a Question

731 491 924 answers to any question