-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db1e201
commit b5fc196
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Create a faulty calculator using JavaScript | ||
This faulty calculator does following: | ||
1. It takes two numbers as input from the user | ||
2. It perfoms wrong operations as follows: | ||
+ ---> - | ||
* ---> + | ||
- ---> / | ||
/ ---> ** | ||
It performs wrong operation 10% of the times | ||
*/ | ||
|
||
let a = Math.random(); | ||
|
||
var num1 = prompt("Enter first number :"); | ||
var num2 = prompt("Enter second number :"); | ||
var op = prompt("Enter the operation you want to perform : "); | ||
|
||
let obj1 = { | ||
"+" : "-", | ||
"*" : "+", | ||
"-" : "/", | ||
"/" : "**" | ||
} | ||
|
||
if (a>0.1){ | ||
//Perform correct calculation | ||
alert(`The result of your calculation is ${eval(`${num1} ${op} ${num2}`)}`); | ||
console.log(`The result of your calculation is ${eval(`${num1} ${op} ${num2}`)}`); | ||
} | ||
|
||
else { | ||
op = obj1[op] | ||
alert(`The result of your calculation is ${eval(`${num1} ${op} ${num2}`)}`); | ||
console.log(`The result of your calculation is ${eval(`${num1} ${op} ${num2}`)}`); | ||
} |