Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Sapfire007 authored Oct 13, 2024
1 parent db1e201 commit b5fc196
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Day51-Exercise-9_Faulty_Calculator/index.html
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>
39 changes: 39 additions & 0 deletions Day51-Exercise-9_Faulty_Calculator/index.js
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}`)}`);
}

0 comments on commit b5fc196

Please sign in to comment.