Im trying to create a calculator for a formula. This function works, I have seen in the console. I just can't figure out how to display the output.
enter image description here
Asked
Active
Viewed 53 times
-4

kian
- 3
- 2
-
2[Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Ivar Apr 20 '21 at 20:55
-
Take a look at these, innerHTML for change of HTML code in your page, or innerText for changing the text only: https://www.w3schools.com/jsref/prop_html_innerhtml.asp and https://www.w3schools.com/jsref/prop_node_innertext.asp – Martin Apr 20 '21 at 20:57
1 Answers
1
Here it goes; Like the comment said there are different way and all depends on your context and UI.
Here is quick possibility how you can take your own code forward to show html;
I have just used a button to trigger the function with runs your calculation function and then updates the div that we predefined. This part could be any thing for that matter.
function add(a,b){
return a+b;
}
console.log(add(1,4));
var displayhtml = document.querySelector('div');
var trigger = document.querySelector('button');
trigger.onclick = function (){
displayhtml.innerHTML = add(1,4);
}
<div>I am div</div>
<button>chnage html</button>

Syed
- 696
- 1
- 5
- 11