This will basically remove whatever string is already inside the text input. Once it is accessed, the value inside the text input is set to ” (2 single quotes) which is an empty string. If the user clicks on the C button or the clear button, it accesses the text input object, which represents our calculator screen, via the DOM. If(document.getElementById( ' valueshow ').value = ' 0 ')ĭocument.getElementById( ' valueshow ').value = buttonValue ĭocument.getElementById( ' valueshow ').value += buttonValue ĭocument.getElementById( ' valueshow ').value = answer Here is the JavaScript code for the 2 functions:ĭocument.getElementById( ' valueshow ').value = ' 0 ' .bgoperationcolor is use for all operation buttons (+,-,*,/)
.bgcolornumber class is use for all button number buttons (0-9) It also control the left, top margin of calculator. div control the all calculator component like (buttons, text field ). The = button calls the calculate JavaScript function and passes the value that is in the text input which represents the string of numbers and operators that were pushed. Two types of inputs text and button are used here on a table within a form element and OnClick event was used to insert button values on the screen or to evaluate the numbers. All the buttons, except for the = button, will call the cal JavaScript when clicked and passes it’s associated value. Most of the HTML is coding for all the input buttons and their associated onclick event handlers. Submit.The following code is to make html calculator. The JS code is: document.getElementById('results').style.display = 'none' Your BMR is the number of calories you burn off in 24 hours Here's a link to all the code on GitHub, along with a ReadMe that explains in detail how the app works:įill out the below fields to discover your BMR. I want to unlearn any bad habits I may have picked up as soon as possible. It works, but I would really appreciate it if someone more knowledgeable could take a look at the code to see if it's optimal (or even close!).
It's an app which takes the user's gender, age, height, and weight and then calculates their BMR. I'm learning JavaScript at the moment (still very much a beginner) and this is the first app I've designed on my own, without using any tutorials.