Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

<!

DOCTYPE html>
<html>
<head>
<!-- <link rel="stylesheet" href="style.css"> -->
</head>
<body>
<!-- the textbox. -->
<input class="textbox" type="text" id="input">

<!-- buttons -->


<button class="erase"onclick="erase()">C</button>
<!-- br(linebreak) new line. -->
<br>
<button class="one" onclick="one()">1</button>
<button class="two" onclick="two()">2</button>
<button class="three" onclick="three()">3</button>
<button class="divide" onclick="divide()">/</button>
<br>
<button class="four" onclick="four()">4</button>
<button class="five" onclick="five()">5</button>
<button class="six" onclick="six()">6</button>
<button class="multiply" onclick="multiply()">*</button>
<br>
<button class="seven" onclick="seven()">7</button>
<button class="eight" onclick="eight()">8</button>
<button class="nine" onclick="nine()">9</button>
<button class="minus" onclick="minus()">-</button>
<br>
<button class="zero" onclick="zero()">0</button>
<button class="point" onclick="point()">.</button>
<button class="equals" onclick="equals()">=</button>
<button class="plus" onclick="plus()">+</button>

<!-- id's. -->


<p id="input"></p>

<p id="isDivide"></p>
<p id="isMultiply"></p>
<p id="isMinus"></p>
<p id="isPlus"></p>

<p id="isFirstValue"></p>
<p id="firstValue"></p>
<p id="secondValue"></p>

<!-- inside scripting. -->


<script>
let input = document.getElementById("input");

let isDivide = document.getElementById("isDivide");


let isMultiply = document.getElementById("isMultiply");
let isMinus = document.getElementById("isMinus");
let isPlus = document.getElementById("isPlus");

let isFirstValue = true;

let firstValue = "";


let secondValue = "";
//function to add decimal.
function point(){

if(isFirstValue == true){

firstValue += ".";

}else{

secondValue += ".";

input.value += ".";
}

//function to add zero.


function zero(){

if(isFirstValue == true){

firstValue += 0;

}else{

secondValue += 0;

input.value +=0;
}

//function to add one.


function one(){

if(isFirstValue == true){

firstValue += 1;

}else{

secondValue += 1;

input.value += 1;
}

//function to add two.


function two(){

if(isFirstValue == true){

firstValue += 2;

}else{

secondValue += 2;
}
input.value += 2;
}

//function to add three.


function three(){

if(isFirstValue == true){

firstValue += 3;

}else{

secondValue += 3;

input.value += 3;

//function to add four.


function four(){

if(isFirstValue == true){

firstValue += 4;

}else{

secondValue += 4;

input.value += 4;

//funtion to add five.


function five(){

if(isFirstValue == true){

firstValue += 5;

}else{

secondValue += 5;

input.value += 5;

//function to add six.


function six(){

if(isFirstValue == true){
firstValue += 6;

}else{

secondValue += 6;

input.value += 6;

//function to add seven.


function seven(){

if(isFirstValue == true){

firstValue += 7;

}else{

secondValue += 7;

input.value += 7;

//function to add eight.


function eight(){

if(isFirstValue == true){

firstValue += 8;

}else{

secondValue += 8;

input.value += 8;
}

//function to add nine.


function nine(){

if(isFirstValue == true){

firstValue += 9;

}else{

secondValue += 9;

}
input.value += 9;

//function to clear(we use function name erase becuase when we use


function).
function erase() {

input.value = null;
firstValue = "";
secondValue = "";

//function to divide.
function divide(){

input.value += "/";
isDivide = true;
isFirstValue = false;

//function to multiply.
function multiply() {

input.value += "*";
isMultiply = true;
isFirstValue = false;

//function to subtract.
function minus(){

input.value += "-";
isMinus = true;
isFirstValue = false;

//function to add.
function plus(){

input.value += "+";
//to know that the operation is addition
isPlus = true;
isFirstValue = false;

function equals(){

let answer = "";

//if-else if statement to identify which operation will be use.


if(isDivide == true){
answer = Number(firstValue) / Number(secondValue)

//to show answer


input.value = answer;
isDivide = false;
isFirstValue = true;

}else if(isMultiply == true){

answer = Number(firstValue) * Number(secondValue);


//to show answer
input.value = answer;
isMultiply = false;
isFirstValue = true;

}else if(isMinus == true){

answer = Number(firstValue) - Number(secondValue);


//to show answer
input.value = answer;
isMinus = false;
isFirstValue = true;

}else{

answer = Number(firstValue) + Number(secondValue);


//to show answer
input.value = answer;
isPlus = false;
isFirstValue = true;

firstValue = answer;
secondValue = "";

</script>
</body>
</html>

You might also like