Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was creating a calculator and I don't understand the code below

Let outputScreen = document.getElementById("input")

Function display(num){
outputScreen.value += num;

Function calculate(){
outputScreen.value = eval(outputScreen.value);

Please explain the javascript code

What I have tried:

I have tried searching on Google for an explanation but am not understanding them
Updated 30-Jul-21 22:06pm
Richard MacCutchan 31-Jul-21 4:51am    
It's called 'learning'. Trying to become a programmer before you have properly studied, and learnt the language, is just a waste of your time.

These are very basic javascript commands. You won't be able to write a calculator if you do not understand the basics.

Let outputScreen = document.getElementById("input") // This gets an element from your page with an id of "input" and stores it in a variable named outputScreen. This is self explanatory.

Function display(num){
outputScreen.value += num;

This is a function that you pass a value into and it adds it to whatever is in the input element.

For eval, see JavaScript eval() Function[^]
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900