0% found this document useful (0 votes)
13 views2 pages

Calculator Terminal JS Code

This document is a simple text-based calculator program written in JavaScript. It prompts the user to enter two numbers and an operator to perform basic arithmetic operations. The program includes input validation and allows the user to reset or exit the calculator as desired.

Uploaded by

akheelmewing207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Calculator Terminal JS Code

This document is a simple text-based calculator program written in JavaScript. It prompts the user to enter two numbers and an operator to perform basic arithmetic operations. The program includes input validation and allows the user to reset or exit the calculator as desired.

Uploaded by

akheelmewing207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//calculator

const prompt = require("prompt-sync")();


let valid = true;
let num1;
let num2;
let operator;
let reset = "y";
let result;
[Link]("CALCULATOR (text based)");

while (true){

const enter = prompt("Enter Calculator? (y/n) : ").toLowerCase();

if (enter === "y"){


while (true){
if (reset === "y"){

while (true) {
num1 = prompt("enter first n : "); //klo mau biar bisa , ==>
parseFloat()
if (isNaN(num1)) {
[Link]("invalid number.");
} else {
break;
}
}
while (true) {
num2 = prompt("enter second n : ");
if (isNaN(num2)) {
[Link]("invalid number.");
} else {
break;
}
}

operator = prompt("enter sign : ");

switch(operator){
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
default :
[Link]("sometimes, i can stupid too");
valid = false;
break;
}
if (valid === true) {
[Link](num1, operator, num2, "=", result);
}
} else if (reset === "n"){
[Link]("ok then..");
break;
} else {
[Link]("stupid human.");
}
reset = prompt("reload? (y/n) :").toLowerCase();
}

} else if (enter === "n"){


[Link]("farewell human");
break;
} else {
[Link]("stupid human.")
}
}

You might also like