+ 2

Help with buttons HTML+JavaScript

So I'm trying to make a simple calculator a some time, and I have a problem. I can't "writte" the results. Click on add and after on history to better unterstanding. (sorry for bad grammar) HTML: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onclick="add()">Add</button> <button onclick="H()">History </button> <p id="L">History gonna here </p> </body> </html> JavaScript: num1=5; num2=30; var RH = (num1 + num2) //function calcRH () { //RH = ("</br>" + RH);} function add () { var N = prompt ("Number 1"); var M = prompt ("Number 2"); var L = (Number(N) + Number(M)); } function H () { document.getElementById("L").innerHTML = (L + RH); } https://code.sololearn.com/W2uwer0hrn8G/#html

28th Jan 2018, 5:05 PM
Vinicius Rocha Perrud
Vinicius Rocha Perrud - avatar
3 Answers
+ 3
var num1=5; var num2=30; var RH = num1 + num2; var L =0; function add () { var N = prompt ("Number 1"); var M = prompt ("Number 2"); L = Number(N) + Number(M); } function H () { document.getElementById("L").innerHTML = L + RH; }
28th Jan 2018, 5:19 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 2
thanks, work good, has some code to add the text instead substitute?
28th Jan 2018, 8:49 PM
Vinicius Rocha Perrud
Vinicius Rocha Perrud - avatar
0
might I suggest using a ul element for your history and the append li elements to it
4th Mar 2018, 9:09 PM
Derek Viets
Derek Viets - avatar