A simple calculator in javascript and html. This is the basic simple calculator in javascript which is made using a simple class in javascript. It also demonstrates how you can create a class for simple tasks and instantiate it.
HTML
<div id="calc">
<input type="number" id="num1" placeholder="Enter a number"/>
<select id="operator" >
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="number" id="num2" placeholder="Enter a number" />
<button id="calc">=</button>
<input type="number" id="result" placeholder="Result" />
</div>
Javascript
class Calculator{
// Properties
num1
num2
result
num1Input
num2Input
resultInput
operatorSelect
// member functions
constructor(){
// initialization of the calculator
}
setEvents(){
// set events on button
}
add(){
// add numbers
}
subtract(){
// subtract numbers
}
multiple(){
// multiple numbers
}
divide(){
// divide numbers
}
output(){
// output the results
}
}
For detailed tutorial on (this code) simple calculator in javascript, please follow this link:
https://10code.dev/javascript/a-simple-calculator-in-vanilla-javascript/
Top comments (0)