harry bhaiya thank you for this course. i leaved behind in this course due to college exams so i reached today on this vdo . i accept the challenge and my answer is console.log(" faulty calculatar ") if (Math.random() < 0.1){ function sum(a,b){ return a-b } function sub(a,b){ return a/b } function mul(a,b){ return a+b } function div(a,b){ return a**b } } else{ function sum(a,b){ return a+b } function sub(a,b){ return a-b } function mul(a,b){ return a*b } function div(a,b){ return a/b } }
let c = sum(16,14) let d = sub(16,14) let p = mul(16,14) let q = div(16,14) console.log("output of operation --->> "+ c) console.log("output of operation --->> "+ d) console.log("output of operation --->> "+ p) console.log("output of operation --->> "+ q)
Please bhaiya is course ko future Mai bilkul mat hatana 😭😭 I'm in junior college not able to attend this course please keep it free only This is the best course jo I.T. subject ham college mai sikhte hai 6months ka aapne sirf 2 videos mai complete Kiya Thankyou ❤❤
Why don't you go to through the documentation of the js and old js ultimate course? Ther's enough information available if you want to learn. If you don't then toh bhagwaan hi apka bhala kare........ #no_bhana
Hellow bhaiya, I started this series 10 day before today .So, I was now on 22nd video. But I was enjoying the series and it help me lot. Now I am in class 10, but I literally understand the topics. once again thank you for this free series. thanking you your truly SUMIT
#ChallengeAccepted #Solution: i increase the probability to 60% because on checking while executing the code i was confused and i also used readline to execute the code within node.js const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); function faultycalculator(operator, a, b) { let result; const isFaulty = Math.random() < 0.6; console.log(`isFaulty: ${isFaulty}`); if (isFaulty) { // Perform faulty operation switch (operator) { case '+': result = a - b; // Faulty addition (subtraction) break; case '-': result = a / b; // Faulty subtraction (addition) break; case '*': result = a + b; // Faulty multiplication (addition) break; case '/': result = a ** b; // Faulty division (exponential) break; default: console.log("Invalid operator"); break; } } else { // Perform correct operation switch (operator) { case '+': result = a + b; break; case '-': result = a - b; break; case '*': result = a * b; break; case '/': result = a / b; break; default: console.log("Invalid operator"); break; } } return result; } rl.question("Enter the first number: ", function (a) { rl.question("Enter the operator (+, -, *, /): ", function (operator) { rl.question("Enter the second number: ", function (b) { const result = faultycalculator(operator, parseFloat(a), parseFloat(b)); console.log(`Result of ${a} ${operator} ${b} is: ${result}`); rl.close(); }); }); });
why did you make it so complicated? it was a simple if and else program...do as much as is asked...your time will be saved also questionnaire will be happy
brother, all of students solved this question by using if else statement. this brother did very well for other students. because he show us that it can also do with using switch case and function
it's a difficult challenge, but also very interesting.It takes about an hour to solve the problem // const prompt = require("prompt-sync")(); let num1 = prompt("Enter your first number: "); let num2 = prompt("Enter your second number: "); num1 = Number.parseInt(num1); num2 = Number.parseInt(num2); let operation = prompt("What operation do you want to perform? "); let CPU = Math.floor(Math.random() * 10); console.log("CPU:", CPU); let sum, minus, multiply, divide; if (CPU > 1) { sum = (a, b) => a + b; minus = (a, b) => a - b; multiply = (a, b) => a * b; divide = (a, b) => (b !== 0 ? a / b : "Cannot divide by zero."); } else { sum = (a, b) => a - b; minus = (a, b) => (b !== 0 ? a / b : "Cannot divide by zero."); multiply = (a, b) => a - b; divide = (a, b) => a * b; } let result1 = sum(num1, num2); let result2 = minus(num1, num2); let result3 = multiply(num1, num2); let result4 = divide(num1, num2); if (operation === "sum") { // console.log(`${num1} ${operation} ${num2} is equal to ${result1}`); console.log("The sum of the numbers is", result1); } if (operation === "minus") { // console.log(`${num1} ${operation} ${num2} is equal to ${result2}`); console.log("The minus of the numbers is", result2); } if (operation === "multiply") { // console.log(`${num1} ${operation} ${num2} is equal to ${result3}`); console.log("The multiply of the numbers is", result3); } if (operation === "divide") { // console.log(`${num1} ${operation} ${num2} is equal to ${result4}`); console.log("The divide of the numbers is", result4); } if (operation !== "sum" && operation !== "minus" && operation !== "multiply" && operation !== "divide") { console.log("The operator is incorrect. You should use lowercase words"); } hope you like it 😊😊😊😊
Hey be honest, how do you wrote this code by just watching 5 basic videos of js in this course? Bro, I cant be able to figure out how to take input from user by using prompt & How did you wrote this code bruh!!! Did you learn javascript before???
Thanks bhaiya for the playlist Here is my code function sum(a,b) { result=a+b; console.log(result); } function sub(a,b) { result=a-b; console.log(result);
} function div(a,b) { result=a/b; console.log(result);
} function mul(a,b) { result=a*b; console.log(result);
} function expo(a,b) { result=a**b; console.log(result);
} // let a= readInt("Enter the number a"); // let b=readInt("ENter the number b"); let a=8; let b=10; if(Math.random()
// Input Numbers let a = Number(prompt("Enter your number 1 ")); let b = Number(prompt("Enter your number 2 ")); // Random Number let random = Math.random(); let addition = a+b ; let Subtraction = a-b; let Multiplication =a*b; let Division= a/b; let Exponentiation = a**b; // Condition if (random
@@CodewithHS1 time do, isme logo ka 40-50 lpa ka package lagta he, itna jaldi thodi samajh aayega, time lagega min- 3 months ache se samajh ke functional website banane me
Challenge Accepted 👍 let random = Math.random(); let Num1 = parseFloat(prompt("enter first number")); let operator = prompt("enter operator"); let Num2 = parseFloat(prompt("enter second number")); if (random > 0.1) { if (operator === "+") result = Num1 + Num2; else if (operator === "-") result = Num1 - Num2; else if (operator === "*") result = Num1 * Num2; else if (operator === "/") result = Num1 / Num2; else if (operator === "**") result = Num1 ** Num2; } else { if (operator === "+") result = Num1 - Num2; else if (operator === "-") result = Num1 / Num2; else if (operator === "*") result = Num1 + Num2; else if (operator === "/") result = Num1 ** Num2; } console.log("result is ", result);
challenge accepted bhaiya :) here's code /* 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 */ function calc(a,b,operator) { if(Math.random()
Challenge Accepted Solution // Enter 1 in operator for additon 2 for substraction 3 for multiplication and 4 for division function calculate (operator,a,b){ let random = Math.random(); if(operator === 1){ let add=(a,b)=>{ if(random{ if(random{ if(random{ if(random
10 months ago Please bhaiya is course ko future Mai bilkul mat hatana 😭😭 I'm in junior college not able to attend this course please keep it free only This is the best course jo I.T. subject ham college mai sikhte hai 6months ka aapne sirf 2 videos mai complete Kiya Thankyou ❤❤
Challenge Accepted! #SigmaBatchOp Harry Bhai! Here is my efforts #solution // Input Numbers let a = Number(prompt("Enter your number 1 ")); let b = Number(prompt("Enter your number 2 ")); // Random Number let random = Math.random(); let addition = a+b ; let Subtraction = a-b; let Multiplication =a*b; let Division= a/b; let Exponentiation = a**b; // Condition if (random
I think this should work : /* Question: Create a Faulty calculator using the javascript such that the faulty calculator does the following things: 01. it takes two numbers input from the user 02. It performs wrong operations as follows + -------> - - ---------> + * ---------> / / ----------> ** Also note that you are hired to make a faulty calculator for a college where the college wants the students to do their calculations by themselves so make sure that the calculator should be working faulty on 10 % of the times that means the calculator should give wrong output only 10% in 100 operations performed */ // Solution try #1 console.log("Making faulty Calculator:"); // Taking Necessary inputs from the user let start = prompt("Press 1 to start the calculator ") // usually the start button of classic calci are like console.log(start); if (start == 1) { console.log("Hello Lets calculate:"); let num1 = parseFloat(prompt("Enter the First Number:")); let num2 = parseFloat(prompt("Enter the second Number:")); console.log("Select the operation to perform"); console.log(" 01.Press 1 for the Addition"); console.log(" 02.Press 2 for the subtraction"); console.log(" 03.Press 3 for the Multiplication"); console.log(" 04.Press 4 for the Division"); let operate = prompt(":"); if (operate == 1) { console.log(add()); } else if (operate == 2) { console.log(sub()); } else if (operate == 3) { console.log(multi()); } else if (operate == 4) { console.log(div()); } else { console.log("Wrong Input:"); } function add() { if (Math.random() < 0.1) { return +num1 + +num2 - Math.random(); } return num1 + num2; } function sub() { if (Math.random() < 0.1) { return -num1 - +num2 - Math.random(); } return num1 - num2; } function multi() { if (Math.random() < 0.1) { return num1 * num2 / Math.random(); } return num1 * num2; } function div() { if (Math.random() < 0.1) { return num1 / num2 ** Math.random(); } return num1 / num2; } } else { console.log("Error Please Press One:"); }
#Challenge Accepted #SigmaBatchOp #JsBatchOp // My Solution for this Exercise // Hope You will understand this function add(n1,n2){ let randomNumber = Math.random(); console.log(randomNumber) if (randomNumber < 0.1){ return (n1 - n2) + randomNumber; } else{ return n1 - n2; } } function multiply(n1,n2){ let randomNumber = Math.random(); console.log(randomNumber) if (randomNumber < 0.1){ return (n1 + n2) * randomNumber; } else{ return n1 + n2; } }; function substract(n1,n2){ let randomNumber = Math.random(); console.log(randomNumber) if (randomNumber < 0.1){ return (n1 / n2) - randomNumber; } else{ return n1 / n2; } }; function devide(n1,n2){ let randomNumber = Math.random(); console.log(randomNumber) if (randomNumber < 0.1){ return (n1 ** n2) / randomNumber; } else{ return n1 ** n2; } }; // Creating the High Order function function calculator(n1,n2,operator){ return operator(n1,n2); }; // Save the value in variable help of return statement //yaha multiply ke jaga koi bhi operator call kar sakte hai jo humne create kiye hai let result = calculator(3,2,multiply) // console log the saved value console.log(result);
@@ahsanali8237 bro jab Randome number ki value 0.1 hogi tab mai ne alag alag function me random number ko use kiya hai jaise Add ke function me mai ne random number ko add kiya aur multiply function me multiply kiya hai take Calculation aur galat aa jaye aap chaho to random number ko simply add kar sakte ho har jaga Jaise multiply function me if (randomNumber < 0.1) { return (n1 + n2) + randomNumber } else{ return n1 +n2} yaha (n1 + n2 ) + randomNumber tab apply hoga jab randomNumber ki value 0.1 se kam hogi aur humara answer 10% galat extra galat ho jayega agar nahi hogi to return (n1+n2) pass ho jayega lekin ye bhi wrong hi hai kiw k calculator hume galat banana hai
Challenge Accepted Harry Bhaiya #Solution 👇🏽 let rand = Math.random(); // Addition : function Add(a, b) { if (rand > 0.3) { let sum = a + b; console.log(sum); } else { let sum = a - b; console.log(sum); } } Add(10, 3); // Multiplication : function Multiply(a, b) { if (rand > 0.3) { let mult = a * b; console.log(mult); } else { let mult = a + b; console.log(mult); } } Multiply(5, 3); // Substraction : function Substraction(a, b) { if (rand > 0.3) { let sub = a - b; console.log(sub); } else { let sub = a / b; console.log(sub); } } Substraction(10, 2); // Division : function Divide(a, b) { if (rand > 0.3) { let div = a / b; console.log(div); } else { let div = a ** b; console.log(div); } } Divide(6, 2);
#SigmaBatchOp Challenge accepted🔥 let a = 23; let b = 12; let c = Math.random(); let div = a / b; let sub = a - b; let add = a + b; let multiply = a * b; let expo = a ** b; function faulty() { if (c > 0.1) { console.log("division: ", div); console.log("addition: ", add); console.log("subtract: ", sub); console.log("multiply: ", multiply); console.log("exponational: ", expo); } else if (c < 0.1) { console.log("suntract: ", multiply); console.log("exponational ", sub); console.log("division: ", expo); console.log("add: ", div); console.log("mutiply: ", add); } } faulty()
00:42 Create a faulty calculator 01:24 Create a faulty calculator using JavaScript 02:06 A faulty calculator that performs wrong operations 03:30 Create a faulty calculator that performs wrong operations 10% of the time 04:12 To perform a calculation with 10% probability, generate a random number between 1 and 100. 04:54 Checking if a number is less than 0.1 05:31 Solve the challenge for a shoutout.
5 star quality. Infact i am not a person who can rate you, you are fatr more superior than all. One request can you give estimate time of course completion
// Create a faulty calculator using js. // This faulty calculator does following : // 1.It takes two numbers as input from the user. // 2.It performes wrong operations as follows: // + > - // * > + // - > / // / >** // it performs wrong operator 10% of the times
const faultyCalculator = (a, b) => { console.log("a is " + a); console.log("b is " + b); let random = Math.random(); let Addition = a + b; let Subtraction = a - b; let Multiplication = a * b; let Division = a / b; let Exponentiation = a ** b; if (random < 0.1) { Addition = a - b; Subtraction = a / b; Multiplication = a + b; Division = a ** b; } console.log("Addition Result after faulty calculation: " + Addition); console.log("SubtractionResult after faulty calculation: " + Subtraction); console.log("MultiplicationResult after faulty calculation: " + Multiplication); console.log("DivisionResult after faulty calculation: " + Division); console.log("ExponentiationResult after faulty calculation: " + Exponentiation); }; for (let i = 0; i < 5; i++) { faultyCalculator(1, 1); }
let a = Math.random(10); console.log(a); function add(a, b) { return a + b; } function subtract(a, b) { return a - b; } function multiply(a, b) { return a * b; } function divide(a, b) { return a / b; } if(a < 0.1){ function add(a, b) { return a - b; } function subtract(a, b) { return a + b; } function multiply(a, b) { return a / b; } function divide(a, b) { return a * b; } } console.log(add(1, 2)); console.log(subtract(1, 2)); console.log(multiply(1, 2)); console.log(divide(1, 2));
/* 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...! */ // Right calculation Function let rightcalc = function (a, b, c) { // Taking User Input a = Number(prompt("First Number")); let inp1 = Number(a); b = prompt("Operator: +, -, *, /, **"); c = Number(prompt("Second Number")); let inp2 = Number(c); console.log("The first Number: " + inp1); console.log("Operator: " + b); console.log("The Second Number: " + inp2); // Checking the validity of the NUmber if (isNaN(inp1) && isNaN(inp2)) { console.log("Enter Valid Number"); } // Start doing calculation based on inputs and operator if (b == "+") { let sum = inp1 + inp2; console.log(sum); } else if (b == "*") { let multiplication = inp1 * inp2; console.log(multiplication); } else if (b == "/") { let divide = inp1 / inp2; console.log(divide); } else if (b == "-") { let substract = inp1 - inp2; console.log(substract); } else if (b == "**") { let exponent = inp1 ** inp2; console.log(exponent); } else { console.log("Enter a valid Operator"); } }; //Wrong Claculation Function let wrongcalc = function (a, b, c) { // Taking User Input a = Number(prompt("First Number")); let inp1 = Number(a); b = prompt("Operator: +, -, *, /, **"); c = Number(prompt("Second Number")); let inp2 = Number(c); console.log("The first Number: " + inp1); console.log("Operator: " + b); console.log("The Second Number: " + inp2); // Checking the validity of the NUmber if (isNaN(inp1) && isNaN(inp2)) { console.log("Enter Valid Number"); } // Start doing calculation based on inputs and operator if (b == "+") { let sum = inp1 - inp2; console.log(sum); } else if (b == "*") { let multiplication = inp1 + inp2; console.log(multiplication); } else if (b == "/") { let divide = inp1 ** inp2; console.log(divide); } else if (b == "-") { let substract = inp1 / inp2; console.log(substract); } else if (b == "**") { let exponent = inp1 ** inp2; console.log(exponent); } else { console.log("Enter a valid Operator"); } };
// Probability checking To perform the right/wrong calculation
let c = Math.random(); if (c < 0.1) { console.log("10% Probability Matches"); wrongcalc(); } else { console.log("10% Probability Does Not Match"); rightcalc(); } console.log(`Probability : ${c}`);
var a = 12 var b = 3 var operation = 2; // var a = prompt("Enter a number:"); // var b = prompt("Enter a number:"); // var operation = prompt("What operation do you want to do? 1:Add 2:Subtract 3:Multiply 4:Divide") let fault = Math.random(); function sum(a, b) { return a + b; } function diff(a, b) { return a - b; } function pro(a, b) { return a * b; } function expo(a, b) { return a ** b; } function slash(a, b) { return a / b; } if (fault > 0.1) { switch (operation) { case 1: console.log(sum(a, b)); break; case 2: console.log(diff(a, b)); break; case 2: console.log(pro(a, b)); break; case 2: console.log(slash(a, b)); break; } } else { switch (operation) { case 1: console.log(diff(a, b)); break; case 2: console.log(slash(a, b)); break; case 2: console.log(sum(a, b)); break; case 2: console.log(expo(a, b)); break; } }
this is the answer note: download prompt sync module first by running npm install prompt-sync in the terminal // create a faulty calculator using js // this faulty calculator does following // 1. It takes two numbers as input from the user // 2. it performs wrong operations // + -> - // * -> + // - -> / // / -> ** // it performs 10% of wrong operation const prompt = require("prompt-sync")(); let a = Number(prompt("Enter your number 1 ")); let b = Number(prompt("Enter your number 2 ")); // Random Number let random = Math.random(); let addition = a+b ; let Subtraction = a-b; let Multiplication =a*b; let Division= a/b; let Exponentiation = a**b; // Condition if (random
/* 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 */ const prompt = require('prompt-sync')(); let i=Math.random() function faulty_caclulater(a,b){ let operation=prompt('choose between: +, -, *, / ') if (i
#ChallengeAccepted #Solution: I used prompt to get the values by user and created two functions with switch case & using if-else statement only one of them will run :- let a = prompt("Enter first number"); let b = prompt("Enter Second number"); let operator = prompt("Enter operator (+,-,*,/)"); function calculator(a,b) { a = Number(a); b = Number(b); switch (operator) { case '+' : return a+b; break; case '-' : return a-b; break; case '*' : return a*b; break; case "/" : return a/b; break; default: break; } } function faultyCalculator(a,b) { a = Number(a); b = Number(b); switch (operator) { case '+' : return a-b; break; case '-' : return a/b; break; case '*' : return a-b; break; case "/" : return a**b; break; default: break; } } let prob = Math.random(); if(prob
solved exercise: (It is made to run in browser but with few modifications, it can run in terminal Aswell). let probability = Math.random() let a = parseInt(prompt("Enter your first number: ")) let o = prompt("Enter operator: ") let b = parseInt(prompt("Enter your second number: ")) if (probability < 0.1){ faulty(a, b,o) } else { correct(a,b,o) } function correct(a,b,o) { if(o=="+"){ console.log((a)+(b)); } else if(o=="-"){ console.log(a-b); } else if(o=="*"){ console.log(a*b); } else{ console.log(a/b); } } function faulty(a,b,o) { if(o=="+"){ console.log(a-b); } else if(o=="-"){ console.log(a/b); } else if(o=="*"){ console.log(a+b); } else{ console.log(a**b); } }
The input numbers can be made with prompt or input by replacing the declaration variables let a = Math.random(); let x = 10; let y = 20; let operator = "-"; function calc(x, y, operator) { if (operator == "+") { console.log(x + y); } else if (operator == "-") { console.log(x - y); } else if (operator == "*") { console.log(x * y); } else if (operator == "/") { console.log(x / y); } else { console.log("Invalid operator"); } } function faultCalc(x, y, operator) { if (operator == "+") { console.log(x - y); } else if (operator == "-") { console.log(x / y); } else if (operator == "*") { console.log(x + y); } else if (operator == "/") { console.log(x ** y); } else { console.log("Invalid operator"); } } if (a < 0.1) { faultCalc(x, y, operator); } else { calc(x, y, operator); }
Challenge Accepted var a = Number(prompt("Enter your number 1 ")); var b = Number(prompt("Enter your number 2 ")); let rand = Math.random() var result = a+b ; if (rand
Done after an hour of struggle FACULTY CALCULATOR do { var num1 = prompt("Enter first integer:"); var num2 = prompt("Enter second integer:"); let a = Math.floor(Math.random() * 100); if (a > 10) { good_calc(num1, num2); } else { faulty_calc(num1, num2); } function good_calc(x, y) { let ans = prompt( "Which operation do you like to perform? 1)Add 2)Subtract 3)Multiplication 4)Division" ); if (ans == 1) { let fans = +x + +y; console.log("Your answer is " + fans); } else if (ans == 2) { let fans = +x - +y; console.log("Your answer is " + fans); } else if (ans == 3) { let fans = +x * +y; console.log("Your answer is " + fans); } else if (ans == 4) { let fans = +x / +y; console.log("Your answer is " + fans); } else { console.log("Incorrect operation!!!"); } } function faulty_calc(x, y) { let ans = prompt( "Which operation do you like to perform? 1)Add 2)Subtract 3)Multiplication 4)Division" ); if (ans == 1) { let fans = +x - +y; console.log("Your answer is " + fans); } else if (ans == 2) { let fans = +x / +y; console.log("Your answer is " + fans); } else if (ans == 3) { let fans = +x + +y; console.log("Your answer is " + fans); } else if (ans == 4) { let fans = +x / +y; console.log("Your answer is " + fans); } else { console.log("Incorrect operation!!!"); } } var ques = prompt("do you want to perform another operation? 1)yes 2)no"); } while (ques == 1);
Challenge accepted Harry Bhai This is code: let a = Number(prompt("Enter the first number:")); let b = Number(prompt("Enter the second number:")) let random = Math.random(); let addition = a + b; let subtraction = a - b; let multiplication = a * b; let division = a / b; let Exponention = a ** b; if (random < 0.1) { console.log("addition calculation:", a - b); console.log("subtraction calculation:", a / b); console.log("multiplication calculation:", a + b); console.log("division calculation:", a * b); console.log("Exponention calculation:", a ** b); } else { console.log("addition calculation:", a + b); console.log("subtraction calculation:", a - b); console.log("multiplication calculation:", a * b); console.log("division calculation:", a / b); console.log("exponentiation calculation:", a ** b); }
here i multiply math random into ten so it genrates random number between 1 to 10 let x = Math.random()*10 console.log(x) // this line is only for checking random numbers are generating properly or not let inp1 = 4 let inp2 = 6 let op = "+" if(x
let a = parseInt(prompt('Enter first number :')) let b = parseInt(prompt('Enter second number :')) console.log(a,b) let randInt = Math.floor(Math.random() * 100); console.log(randInt) function FaultyCalc(firstnumber, secondnumber) { console.log('Addition of the first and second number is ' + (a-b) ) console.log('Multiplication of the first and second number is ' + (a+b) ) console.log('Subtraction of the first and second number is ' + (a/b) ) console.log('Division of the first and second number is ' + (a**b) ) } function TruelyCalc(firstnumber, secondnumber) { console.log('Addition of the first and second number is ' + (a+b) ) console.log('Multiplication of the first and second number is ' + (a*b) ) console.log('Subtraction of the first and second number is ' + (a-b) ) console.log('Division of the first and second number is ' + (a/b) ) } if(randInt
done // craete a faulty calculator using javsscript let a = parseInt(prompt("enter the first number")); let b = parseInt(prompt("enter the second number")); let random = Math.random(); let addition = a+b; let subtractiom = a-b; let multiplication = a*b; let division = a/b; if(random < 0.1){ console.log("addition calculation:",a-b); console.log("subtraction calculation:",a+b); console.log("multiplication calculation:",a/b); console.log("division calculation:",a*b); } else { console.log("addition calculation:",a+b); console.log("subtraction calculation:",a-b); console.log("multiplication calculation:",a*b); console.log("division calculation:",a/b); }
#HarryBhai done Exercise 9 just taken some extra help as I was getting error again and again // Faulty Calculator console.log("Welcome to Faulty Calculator") if (Math.random() < 0.1) { function sum(a, b) { return (a - b) } function subtraction(a, b) { return (a / b) } function multiplication(a, b) { return (a + b) } function divide(a, b) { return (a ** b) } } else { function sum(a, b) { return (a + b) } function subtraction(a, b) { return (a - b) } function multiplication(a, b) { return (a * b) } function divide(a, b) { return (a / b) } } let q = sum(2, 3) let r = subtraction(5, 3) let s = multiplication(10, 8) let t = divide(30, 4) console.log(q) console.log(r) console.log(s) console.log(t)
Challange accepted harry vai, i can't understand the using of Math.random() in this faulty calculator faulty calculator code here: let a = prompt("enter the value of a:") let operators = prompt("enter the operator:") let b = prompt("enter the value of b:") a = parseInt(a) b = parseInt(b) const addInverse = (a, b) => { return a - b } const multiplyInverse = (a, b) => { return a + b } const divideInverse = (a, b) => { return a ** b } const substractInverse = (a, b) => { return a / b } if(operators == '+'){ console.log(addInverse(a, b)) } else if(operators == '*'){ console.log(multiplyInverse(a, b)) } else if(operators == '/'){ console.log(divideInverse(a, b)) } else if(operators == '-'){ console.log(substractInverse(a, b)) } else{ console.log('invalid input') }
challenge accepted and the answer is let num1 = prompt("Please enter the number1"); num1=num1*1; let num2 = prompt("Please enter the number2");num2=num2*1; let operator = prompt("Please enter the operator"); if (Math.random()>0.1){ if (operator == "+" ){ alert(num1+num2); } else if (operator == "-" ){ alert(num1-num2); } else if (operator == "*" ){ alert(num1*num2); } else if (operator == "/" ){ alert(num1/num2); } } else { if (operator == "+" ){ alert(num1-num2); } else if (operator == "-" ){ alert(num1/num2); } else if (operator == "*" ){ alert(num1+num2); } else if (operator == "/" ){ alert(num1**num2); } } please tell ne if this is correct or not..???
Thank you for course it is very good. function faultycal(a,b,op){ switch(op) { case '+': console.log(a-b); break; case '-': console.log(a+b); break; case '*': console.log(a/b); break; case '/': console.log(a*b); break; } } function normalcal(a,b,op){ switch(op) { case '+': console.log(a+b); break; case '-': console.log(a-b); break; case '*': console.log(a*b); break; case '/': console.log(a/b); break; } } let a=10; let b=10; let op='+'; let isfaulty=Math.random(); if(isfaulty
challenge accepted : let A = Math.random(); const faulty1 = (a, b) => { if (A < 0.1) { return a - b; } else { return a + b; } } let addition = faulty1(2, 3); console.log("The addition of two numbers is:", addition); const faulty2 = (a, b) => { if (A < 0.1) { return a / b; } else { return a - b; } } let substraction = faulty2(9, 3); console.log("The substraction of two numbers is:", substraction); const faulty3 = (a, b) => { if (A < 0.1) { return a + b; } else { return a * b; } } let Multiplication = faulty3(3, 4); console.log("The multiplication of the two numbers is:", Multiplication); const faulty4 = (a, b) => { if (A < 0.1) { return a ** b; } else { return a / b; } } let Division = faulty4(3, 4); console.log("The multiplication of the two numbers is:", Division);
If you are enjoying this course, make sure to write a review comment in the first video of this course. I will be very happy if you go and do that 🙂
Thanks sir.
Sigma Batch Op
# Sigma batch powerfull, this course is very helpful...
Kar Diya Hai Guru Ji Thanks Again❤❤❤
Ok Sir
harry bhaiya thank you for this course. i leaved behind in this course due to college exams so i reached today on this vdo .
i accept the challenge and my answer is
console.log(" faulty calculatar ")
if (Math.random() < 0.1){
function sum(a,b){
return a-b
}
function sub(a,b){
return a/b
}
function mul(a,b){
return a+b
}
function div(a,b){
return a**b
}
}
else{
function sum(a,b){
return a+b
}
function sub(a,b){
return a-b
}
function mul(a,b){
return a*b
}
function div(a,b){
return a/b
}
}
let c = sum(16,14)
let d = sub(16,14)
let p = mul(16,14)
let q = div(16,14)
console.log("output of operation --->> "+ c)
console.log("output of operation --->> "+ d)
console.log("output of operation --->> "+ p)
console.log("output of operation --->> "+ q)
bhai isme user se input toi liya hi nahi.
@@champion_aarush hoisting bro
Thanks❤
Please bhaiya is course ko future Mai bilkul mat hatana 😭😭
I'm in junior college not able to attend this course please keep it free only
This is the best course jo I.T. subject ham college mai sikhte hai 6months ka aapne sirf 2 videos mai complete Kiya
Thankyou ❤❤
😂😂
Konse duniya ka h tu?
haha 😂😂🤣🤣@@shivanshupadhyay7245
Why don't you go to through the documentation of the js and old js ultimate course?
Ther's enough information available if you want to learn. If you don't then toh bhagwaan hi apka bhala kare........ #no_bhana
Bhai Harry bhai apna koi bhi course nhi hatate
Faulty Calculator ready bro 🎉. Thank you brother for such videos💌.
Ye same exercise old Python Tutorial playlist mai bhi thi❤
You is the best teacher in all over the WORLD and this course is best course .
Hellow bhaiya,
I started this series 10 day before today .So, I was now on 22nd video.
But I was enjoying the series and it help me lot. Now I am in class 10, but I literally understand the topics.
once again thank you for this free series.
thanking you
your truly
SUMIT
Beta padhaiye pe dhyan de ,yahan nhin
@@soumyaranjansahoo5199 ye v to padhai hi hai ispe bechara dhyan de rha hai
Same me bhi 10 class me hu
@@armyrusharmyrush6737 me to 8th pe hun html, css tailwind bootstrap, python or ab js sikh rha hun
What's your goal
5 million - advance congratulations Harry Bhaiya😄😄
6.65M
iss exercise ko solve krne m bahut mja aaya🤗🤗🤗
#SigmaBatchOp
#JavaScriptOp
if you are having a problem in vs code regarding the prompt then run this in the terminal:-
npm install prompt-sync
#ChallengeAccepted
#Solution:
i increase the probability to 60% because on checking while executing the code i was confused
and i also used readline to execute the code within node.js
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function faultycalculator(operator, a, b) {
let result;
const isFaulty = Math.random() < 0.6;
console.log(`isFaulty: ${isFaulty}`);
if (isFaulty) {
// Perform faulty operation
switch (operator) {
case '+':
result = a - b; // Faulty addition (subtraction)
break;
case '-':
result = a / b; // Faulty subtraction (addition)
break;
case '*':
result = a + b; // Faulty multiplication (addition)
break;
case '/':
result = a ** b; // Faulty division (exponential)
break;
default:
console.log("Invalid operator");
break;
}
} else {
// Perform correct operation
switch (operator) {
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
default:
console.log("Invalid operator");
break;
}
}
return result;
}
rl.question("Enter the first number: ", function (a) {
rl.question("Enter the operator (+, -, *, /): ", function (operator) {
rl.question("Enter the second number: ", function (b) {
const result = faultycalculator(operator, parseFloat(a), parseFloat(b));
console.log(`Result of ${a} ${operator} ${b} is: ${result}`);
rl.close();
});
});
});
you should use process.argv[2]
why did you make it so complicated? it was a simple if and else program...do as much as is asked...your time will be saved also questionnaire will be happy
brother, all of students solved this question by using if else statement. this brother did very well for other students. because he show us that it can also do with using switch case and function
This course is very helpful for me.
it's a difficult challenge, but also very interesting.It takes about an hour to solve the problem
// const prompt = require("prompt-sync")();
let num1 = prompt("Enter your first number: ");
let num2 = prompt("Enter your second number: ");
num1 = Number.parseInt(num1);
num2 = Number.parseInt(num2);
let operation = prompt("What operation do you want to perform? ");
let CPU = Math.floor(Math.random() * 10);
console.log("CPU:", CPU);
let sum, minus, multiply, divide;
if (CPU > 1) {
sum = (a, b) => a + b;
minus = (a, b) => a - b;
multiply = (a, b) => a * b;
divide = (a, b) => (b !== 0 ? a / b : "Cannot divide by zero.");
} else {
sum = (a, b) => a - b;
minus = (a, b) => (b !== 0 ? a / b : "Cannot divide by zero.");
multiply = (a, b) => a - b;
divide = (a, b) => a * b;
}
let result1 = sum(num1, num2);
let result2 = minus(num1, num2);
let result3 = multiply(num1, num2);
let result4 = divide(num1, num2);
if (operation === "sum") {
// console.log(`${num1} ${operation} ${num2} is equal to ${result1}`);
console.log("The sum of the numbers is", result1);
}
if (operation === "minus") {
// console.log(`${num1} ${operation} ${num2} is equal to ${result2}`);
console.log("The minus of the numbers is", result2);
}
if (operation === "multiply") {
// console.log(`${num1} ${operation} ${num2} is equal to ${result3}`);
console.log("The multiply of the numbers is", result3);
}
if (operation === "divide") {
// console.log(`${num1} ${operation} ${num2} is equal to ${result4}`);
console.log("The divide of the numbers is", result4);
}
if (operation !== "sum" && operation !== "minus" && operation !== "multiply" && operation !== "divide") {
console.log("The operator is incorrect. You should use lowercase words");
}
hope you like it 😊😊😊😊
impressive 👍👍
thanks bro @@inderpal_singh_
bhai 10 min. me kr lia bro
Hey be honest, how do you wrote this code by just watching 5 basic videos of js in this course? Bro, I cant be able to figure out how to take input from user by using prompt & How did you wrote this code bruh!!! Did you learn javascript before???
@@codeXsnippet bhai kisi aur language me padh rakha hoga baki syntax alag h
Congratulations for 5 million subscribers in advance ❤️❤️❤️❤️ #HarryBhai🎉🎉
Ek hi dil ko kitni baar jitoge bhaiyaa ❤❤❤❤❤
Bhaiya mere ko Ghar se uthawaa lo❤❤❤❤❤❤😂😂😂 Dil jit lete ho bhaiya. I am Software Engineer. And I am Founder of Fastdesign pvt Ltd
Koi job ha
hn h bs ya sochna h ka paise kesaa ayn ga
@@fact2.049
congratulations! harry bhai you have got 5M subscribe mene aapke 20 subscribe badaye hai 👌👌👌👌🌹🌹
honestly you taught like 50% of what you asked us to do in this excercise
sahi mai yrr bhai isne funtions tak padhaya aur exerxise itna hard
Thanks bhaiya for the playlist
Here is my code
function sum(a,b)
{
result=a+b;
console.log(result);
}
function sub(a,b)
{
result=a-b;
console.log(result);
}
function div(a,b)
{
result=a/b;
console.log(result);
}
function mul(a,b)
{
result=a*b;
console.log(result);
}
function expo(a,b)
{
result=a**b;
console.log(result);
}
// let a= readInt("Enter the number a");
// let b=readInt("ENter the number b");
let a=8;
let b=10;
if(Math.random()
// Input Numbers
let a = Number(prompt("Enter your number 1 "));
let b = Number(prompt("Enter your number 2 "));
// Random Number
let random = Math.random();
let addition = a+b ;
let Subtraction = a-b;
let Multiplication =a*b;
let Division= a/b;
let Exponentiation = a**b;
// Condition
if (random
bhai input kaise lete he, me prompt karta hu to terminal me "prompt is not defined " dikhata he
@@amannettic4994 Use const prompt = require('prompt-sync')(); at the start of your code..
Ya work hi nhi krta
Mugha to smaj nhi a rhi abhi 6 7 lecture liay hay or asa kuch sikha bhi nhi jo project mil gya
@@CodewithHS1 time do, isme logo ka 40-50 lpa ka package lagta he, itna jaldi thodi samajh aayega, time lagega min- 3 months ache se samajh ke functional website banane me
Its very tough exercise but i will to do it with full interest .
Challenge Accepted 👍
let random = Math.random();
let Num1 = parseFloat(prompt("enter first number"));
let operator = prompt("enter operator");
let Num2 = parseFloat(prompt("enter second number"));
if (random > 0.1) {
if (operator === "+") result = Num1 + Num2;
else if (operator === "-") result = Num1 - Num2;
else if (operator === "*") result = Num1 * Num2;
else if (operator === "/") result = Num1 / Num2;
else if (operator === "**") result = Num1 ** Num2;
} else {
if (operator === "+") result = Num1 - Num2;
else if (operator === "-") result = Num1 / Num2;
else if (operator === "*") result = Num1 + Num2;
else if (operator === "/") result = Num1 ** Num2;
}
console.log("result is ", result);
challenge accepted bhaiya :)
here's code /*
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
*/
function calc(a,b,operator)
{
if(Math.random()
Challenge Accepted
Solution
// Enter 1 in operator for additon 2 for substraction 3 for multiplication and 4 for division
function calculate (operator,a,b){
let random = Math.random();
if(operator === 1){
let add=(a,b)=>{
if(random{
if(random{
if(random{
if(random
Nice bro mujhe nhi samajh aaya 🥺🥺
Monkey D . Luffy 👍
vid_59 completed!
10 months ago
Please bhaiya is course ko future Mai bilkul mat hatana 😭😭
I'm in junior college not able to attend this course please keep it free only
This is the best course jo I.T. subject ham college mai sikhte hai 6months ka aapne sirf 2 videos mai complete Kiya
Thankyou ❤❤
Challenge Accepted! #SigmaBatchOp Harry Bhai!
Here is my efforts
#solution
// Input Numbers
let a = Number(prompt("Enter your number 1 "));
let b = Number(prompt("Enter your number 2 "));
// Random Number
let random = Math.random();
let addition = a+b ;
let Subtraction = a-b;
let Multiplication =a*b;
let Division= a/b;
let Exponentiation = a**b;
// Condition
if (random
nice
bro in vs code prompt is not defined
@@techgamertej2811use browser console
@@techgamertej2811 bro use process.argv[2]
@techgamertej2811 lol
Congratulations for 5M❤🎉
I think this should work :
/*
Question: Create a Faulty calculator using the javascript such that the faulty calculator does the following things:
01. it takes two numbers input from the user
02. It performs wrong operations as follows
+ -------> -
- ---------> +
* ---------> /
/ ----------> **
Also note that you are hired to make a faulty calculator for a college where the college wants the students to do their calculations by themselves so make sure that the calculator should be working faulty on 10 % of the times that means the calculator should give wrong output only 10% in 100 operations performed
*/
// Solution try #1
console.log("Making faulty Calculator:");
// Taking Necessary inputs from the user
let start = prompt("Press 1 to start the calculator ") // usually the start button of classic calci are like
console.log(start);
if (start == 1) {
console.log("Hello Lets calculate:");
let num1 = parseFloat(prompt("Enter the First Number:"));
let num2 = parseFloat(prompt("Enter the second Number:"));
console.log("Select the operation to perform");
console.log(" 01.Press 1 for the Addition");
console.log(" 02.Press 2 for the subtraction");
console.log(" 03.Press 3 for the Multiplication");
console.log(" 04.Press 4 for the Division");
let operate = prompt(":");
if (operate == 1) {
console.log(add());
}
else if (operate == 2) {
console.log(sub());
}
else if (operate == 3) {
console.log(multi());
}
else if (operate == 4) {
console.log(div());
}
else {
console.log("Wrong Input:");
}
function add() {
if (Math.random() < 0.1) {
return +num1 + +num2 - Math.random();
}
return num1 + num2;
}
function sub() {
if (Math.random() < 0.1) {
return -num1 - +num2 - Math.random();
}
return num1 - num2;
}
function multi() {
if (Math.random() < 0.1) {
return num1 * num2 / Math.random();
}
return num1 * num2;
}
function div() {
if (Math.random() < 0.1) {
return num1 / num2 ** Math.random();
}
return num1 / num2;
}
}
else {
console.log("Error Please Press One:");
}
#ChallengeAccepted
Input needs to be manually added to the code (look at the end):
#Solution
console.log("Welcome to faulty calculator");
function calculator_faulty(x,y,operator) {
if (Math.random() < 0.1) {
if(operator == '+'){
console.log(x - y);
}
else if(operator == '-'){
console.log(x / y);
}
else if(operator == '*'){
console.log(x + y);
}
else if(operator == '/'){
console.log(x ** y);
}
else{
console.log("Invalid operator");
}
}
else{
if(operator == '+'){
console.log(x + y);
}
else if(operator == '-'){
console.log(x - y);
}
else if(operator == '*'){
console.log(x * y);
}
else if(operator == '/'){
console.log(x / y);
}
else{
console.log("Invalid operator");
}
}
}
calculator_faulty(4,2,'/');
understandable
Thanks a lot for such an amazing course..❤❤❤
#Challenge Accepted
#SigmaBatchOp
#JsBatchOp
// My Solution for this Exercise
// Hope You will understand this
function add(n1,n2){
let randomNumber = Math.random();
console.log(randomNumber)
if (randomNumber < 0.1){
return (n1 - n2) + randomNumber;
}
else{
return n1 - n2;
}
}
function multiply(n1,n2){
let randomNumber = Math.random();
console.log(randomNumber)
if (randomNumber < 0.1){
return (n1 + n2) * randomNumber;
}
else{
return n1 + n2;
}
};
function substract(n1,n2){
let randomNumber = Math.random();
console.log(randomNumber)
if (randomNumber < 0.1){
return (n1 / n2) - randomNumber;
}
else{
return n1 / n2;
}
};
function devide(n1,n2){
let randomNumber = Math.random();
console.log(randomNumber)
if (randomNumber < 0.1){
return (n1 ** n2) / randomNumber;
}
else{
return n1 ** n2;
}
};
// Creating the High Order function
function calculator(n1,n2,operator){
return operator(n1,n2);
};
// Save the value in variable help of return statement
//yaha multiply ke jaga koi bhi operator call kar sakte hai jo humne create kiye hai
let result = calculator(3,2,multiply)
// console log the saved value
console.log(result);
Kuch nahi hash tag dalna bhul gaya tha isly edit kiya
return n1 - n2 + randomNumber;
return (n1 + n2) * randomNumber;
return n1 / n2 - randomNumber;
return n1 ** n2 / randomNumber;
ye use kun kia he apne?
@@ahsanali8237 bro jab Randome number ki value 0.1 hogi tab mai ne alag alag function me random number ko use kiya hai jaise
Add ke function me mai ne random number ko add kiya aur multiply function me multiply kiya hai take Calculation aur galat aa jaye aap chaho to random number ko simply add kar sakte ho har jaga
Jaise multiply function me
if (randomNumber < 0.1) {
return (n1 + n2) + randomNumber
}
else{ return n1 +n2}
yaha (n1 + n2 ) + randomNumber tab apply hoga jab randomNumber ki value 0.1 se kam hogi aur humara answer 10% galat extra galat ho jayega agar nahi hogi to return (n1+n2) pass ho jayega lekin ye bhi wrong hi hai kiw k calculator hume galat banana hai
@@atifshaikh169 Okay bro Got It. Thanks
@@ahsanali8237 Keep Learning ❤️
Challenge Accepted Harry Bhaiya
#Solution 👇🏽
let rand = Math.random();
// Addition :
function Add(a, b) {
if (rand > 0.3) {
let sum = a + b;
console.log(sum);
} else {
let sum = a - b;
console.log(sum);
}
}
Add(10, 3);
// Multiplication :
function Multiply(a, b) {
if (rand > 0.3) {
let mult = a * b;
console.log(mult);
} else {
let mult = a + b;
console.log(mult);
}
}
Multiply(5, 3);
// Substraction :
function Substraction(a, b) {
if (rand > 0.3) {
let sub = a - b;
console.log(sub);
} else {
let sub = a / b;
console.log(sub);
}
}
Substraction(10, 2);
// Division :
function Divide(a, b) {
if (rand > 0.3) {
let div = a / b;
console.log(div);
} else {
let div = a ** b;
console.log(div);
}
}
Divide(6, 2);
🥲Rand
Harry bhai JS basic apne jaldbazi me shika diya muje apke old js playlist dekhna pada ise solve krne k liye
let random = Math.random();
console.log(random)
let num1 = parseFloat(prompt("enter number"));
let op = prompt("enter op");
let num2 = parseFloat(prompt("enter number"));
if (random < 0.1) {
if (op === "+") result = num1 - num2
else if (op === "*") result= num1 + num2
else if (op === "-") result= num1 / num2
else if (op === "/") result= num1 ** num2
}
else {
if (op === "+") result= num1 + num2
else if(op === "*") result= num1 * num2
else if(op === "-") result= num1 - num2
else if(op === "/") result= num1 / num2
}
console.log(result)
answer = alert(result)
yes biro wahi me sochu mjhe toa iska strting bhi nhi pata ki kesey kru
aap mjhe inki old playlist share kr skte ho
#SigmaBatchOp
Challenge accepted🔥
let a = 23;
let b = 12;
let c = Math.random();
let div = a / b;
let sub = a - b;
let add = a + b;
let multiply = a * b;
let expo = a ** b;
function faulty() {
if (c > 0.1) {
console.log("division: ", div);
console.log("addition: ", add);
console.log("subtract: ", sub);
console.log("multiply: ", multiply);
console.log("exponational: ", expo);
}
else if (c < 0.1) {
console.log("suntract: ", multiply);
console.log("exponational ", sub);
console.log("division: ", expo);
console.log("add: ", div);
console.log("mutiply: ", add);
}
}
faulty()
00:42 Create a faulty calculator
01:24 Create a faulty calculator using JavaScript
02:06 A faulty calculator that performs wrong operations
03:30 Create a faulty calculator that performs wrong operations 10% of the time
04:12 To perform a calculation with 10% probability, generate a random number between 1 and 100.
04:54 Checking if a number is less than 0.1
05:31 Solve the challenge for a shoutout.
harry bhai ap kamal ho #challenge accepted♥
5 star quality. Infact i am not a person who can rate you, you are fatr more superior than all.
One request can you give estimate time of course completion
harry bahi app ne to bataya hi nai ke js me input kese lete han
// Create a faulty calculator using js.
// This faulty calculator does following :
// 1.It takes two numbers as input from the user.
// 2.It performes wrong operations as follows:
// + > -
// * > +
// - > /
// / >**
// it performs wrong operator 10% of the times
const faultyCalculator = (a, b) => {
console.log("a is " + a);
console.log("b is " + b);
let random = Math.random();
let Addition = a + b;
let Subtraction = a - b;
let Multiplication = a * b;
let Division = a / b;
let Exponentiation = a ** b;
if (random < 0.1) {
Addition = a - b;
Subtraction = a / b;
Multiplication = a + b;
Division = a ** b;
}
console.log("Addition Result after faulty calculation: " + Addition);
console.log("SubtractionResult after faulty calculation: " + Subtraction);
console.log("MultiplicationResult after faulty calculation: " + Multiplication);
console.log("DivisionResult after faulty calculation: " + Division);
console.log("ExponentiationResult after faulty calculation: " + Exponentiation);
};
for (let i = 0; i < 5; i++) {
faultyCalculator(1, 1);
}
Congratulation For 5Million Subscriber :)
let a = Math.random(10);
console.log(a);
function add(a, b) {
return a + b;
}
function subtract(a, b) {
return a - b;
}
function multiply(a, b) {
return a * b;
}
function divide(a, b) {
return a / b;
}
if(a < 0.1){
function add(a, b) {
return a - b;
}
function subtract(a, b) {
return a + b;
}
function multiply(a, b) {
return a / b;
}
function divide(a, b) {
return a * b;
}
}
console.log(add(1, 2));
console.log(subtract(1, 2));
console.log(multiply(1, 2));
console.log(divide(1, 2));
/* 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...!
*/
// Right calculation Function
let rightcalc = function (a, b, c) {
// Taking User Input
a = Number(prompt("First Number"));
let inp1 = Number(a);
b = prompt("Operator: +, -, *, /, **");
c = Number(prompt("Second Number"));
let inp2 = Number(c);
console.log("The first Number: " + inp1);
console.log("Operator: " + b);
console.log("The Second Number: " + inp2);
// Checking the validity of the NUmber
if (isNaN(inp1) && isNaN(inp2)) {
console.log("Enter Valid Number");
}
// Start doing calculation based on inputs and operator
if (b == "+") {
let sum = inp1 + inp2;
console.log(sum);
} else if (b == "*") {
let multiplication = inp1 * inp2;
console.log(multiplication);
} else if (b == "/") {
let divide = inp1 / inp2;
console.log(divide);
} else if (b == "-") {
let substract = inp1 - inp2;
console.log(substract);
} else if (b == "**") {
let exponent = inp1 ** inp2;
console.log(exponent);
} else {
console.log("Enter a valid Operator");
}
};
//Wrong Claculation Function
let wrongcalc = function (a, b, c) {
// Taking User Input
a = Number(prompt("First Number"));
let inp1 = Number(a);
b = prompt("Operator: +, -, *, /, **");
c = Number(prompt("Second Number"));
let inp2 = Number(c);
console.log("The first Number: " + inp1);
console.log("Operator: " + b);
console.log("The Second Number: " + inp2);
// Checking the validity of the NUmber
if (isNaN(inp1) && isNaN(inp2)) {
console.log("Enter Valid Number");
}
// Start doing calculation based on inputs and operator
if (b == "+") {
let sum = inp1 - inp2;
console.log(sum);
} else if (b == "*") {
let multiplication = inp1 + inp2;
console.log(multiplication);
} else if (b == "/") {
let divide = inp1 ** inp2;
console.log(divide);
} else if (b == "-") {
let substract = inp1 / inp2;
console.log(substract);
} else if (b == "**") {
let exponent = inp1 ** inp2;
console.log(exponent);
} else {
console.log("Enter a valid Operator");
}
};
// Probability checking To perform the right/wrong calculation
let c = Math.random();
if (c < 0.1) {
console.log("10% Probability Matches");
wrongcalc();
} else {
console.log("10% Probability Does Not Match");
rightcalc();
}
console.log(`Probability : ${c}`);
var a = 12
var b = 3
var operation = 2;
// var a = prompt("Enter a number:");
// var b = prompt("Enter a number:");
// var operation = prompt("What operation do you want to do? 1:Add 2:Subtract 3:Multiply 4:Divide")
let fault = Math.random();
function sum(a, b) {
return a + b;
}
function diff(a, b) {
return a - b;
}
function pro(a, b) {
return a * b;
}
function expo(a, b) {
return a ** b;
}
function slash(a, b) {
return a / b;
}
if (fault > 0.1) {
switch (operation) {
case 1:
console.log(sum(a, b));
break;
case 2:
console.log(diff(a, b));
break;
case 2:
console.log(pro(a, b));
break;
case 2:
console.log(slash(a, b));
break;
}
}
else {
switch (operation) {
case 1:
console.log(diff(a, b));
break;
case 2:
console.log(slash(a, b));
break;
case 2:
console.log(sum(a, b));
break;
case 2:
console.log(expo(a, b));
break;
}
}
this is the answer
note: download prompt sync module first by running npm install prompt-sync
in the terminal
// create a faulty calculator using js
// this faulty calculator does following
// 1. It takes two numbers as input from the user
// 2. it performs wrong operations
// + -> -
// * -> +
// - -> /
// / -> **
// it performs 10% of wrong operation
const prompt = require("prompt-sync")();
let a = Number(prompt("Enter your number 1 "));
let b = Number(prompt("Enter your number 2 "));
// Random Number
let random = Math.random();
let addition = a+b ;
let Subtraction = a-b;
let Multiplication =a*b;
let Division= a/b;
let Exponentiation = a**b;
// Condition
if (random
Sigma Batch OP
HArry Bhai OP
faulty calculator ready
Challenge Accepted!!......Nice Videos Bhaiya ;)
Challenge Accepted Harry Bhai 🔥🔥#HarryBhai #SigmaBatchOp
/* 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
*/
const prompt = require('prompt-sync')();
let i=Math.random()
function faulty_caclulater(a,b){
let operation=prompt('choose between: +, -, *, / ')
if (i
Very close to 5 million subscribers
#ChallangeAccepted
#HarryBahi lovE yoU sO mucH FOr thiS Course This is a Market best course in web Development.
Thank you ❤
for 10% probability,
math.random should be
Advance congrats for having 5M followers🥰🥰
HARRY BHAI OP
Code For Faulty Calculator :
let c =Math.random();
function add(a,b){
if(c
Challenge Accepted👍
#SigmaBatch
#op
//User Input Here..
let first =2;
let second=1;
//Code
let mathrandom = Math.random()
if(mathrandom
❤❤
thank you Bhaiya
I am a lil late but anyways heres the code for the faulty calculator
let i=0;
// adding a while loop to make the program repeatable
while (i
#ChallengeAccepted
#Solution: I used prompt to get the values by user and created two functions with switch case & using if-else statement only one of them will run :-
let a = prompt("Enter first number");
let b = prompt("Enter Second number");
let operator = prompt("Enter operator (+,-,*,/)");
function calculator(a,b) {
a = Number(a);
b = Number(b);
switch (operator) {
case '+' :
return a+b;
break;
case '-' :
return a-b;
break;
case '*' :
return a*b;
break;
case "/" :
return a/b;
break;
default:
break;
}
}
function faultyCalculator(a,b) {
a = Number(a);
b = Number(b);
switch (operator) {
case '+' :
return a-b;
break;
case '-' :
return a/b;
break;
case '*' :
return a-b;
break;
case "/" :
return a**b;
break;
default:
break;
}
}
let prob = Math.random();
if(prob
SIgma Batch OP⭐⭐⭐⭐⭐
Happy 5M harry bhai❤❤❤❤❤❤❤❤❤❤
solved exercise:
(It is made to run in browser but with few modifications, it can run in terminal Aswell).
let probability = Math.random()
let a = parseInt(prompt("Enter your first number: "))
let o = prompt("Enter operator: ")
let b = parseInt(prompt("Enter your second number: "))
if (probability < 0.1){
faulty(a, b,o)
}
else {
correct(a,b,o)
}
function correct(a,b,o) {
if(o=="+"){
console.log((a)+(b));
}
else if(o=="-"){
console.log(a-b);
}
else if(o=="*"){
console.log(a*b);
}
else{
console.log(a/b);
}
}
function faulty(a,b,o) {
if(o=="+"){
console.log(a-b);
}
else if(o=="-"){
console.log(a/b);
}
else if(o=="*"){
console.log(a+b);
}
else{
console.log(a**b);
}
}
The input numbers can be made with prompt or input by replacing the declaration variables
let a = Math.random();
let x = 10;
let y = 20;
let operator = "-";
function calc(x, y, operator) {
if (operator == "+") {
console.log(x + y);
} else if (operator == "-") {
console.log(x - y);
} else if (operator == "*") {
console.log(x * y);
} else if (operator == "/") {
console.log(x / y);
} else {
console.log("Invalid operator");
}
}
function faultCalc(x, y, operator) {
if (operator == "+") {
console.log(x - y);
} else if (operator == "-") {
console.log(x / y);
} else if (operator == "*") {
console.log(x + y);
} else if (operator == "/") {
console.log(x ** y);
} else {
console.log("Invalid operator");
}
}
if (a < 0.1) {
faultCalc(x, y, operator);
} else {
calc(x, y, operator);
}
Challenge Accepted
var a = Number(prompt("Enter your number 1 "));
var b = Number(prompt("Enter your number 2 "));
let rand = Math.random()
var result = a+b ;
if (rand
oh i could do that in 1 if i created seperate "if" like this but it is working thu
let a=10
let b=2
let rand=Math.random()
if(rand
Done after an hour of struggle
FACULTY CALCULATOR
do {
var num1 = prompt("Enter first integer:");
var num2 = prompt("Enter second integer:");
let a = Math.floor(Math.random() * 100);
if (a > 10) {
good_calc(num1, num2);
} else {
faulty_calc(num1, num2);
}
function good_calc(x, y) {
let ans = prompt(
"Which operation do you like to perform?
1)Add
2)Subtract
3)Multiplication
4)Division"
);
if (ans == 1) {
let fans = +x + +y;
console.log("Your answer is " + fans);
} else if (ans == 2) {
let fans = +x - +y;
console.log("Your answer is " + fans);
} else if (ans == 3) {
let fans = +x * +y;
console.log("Your answer is " + fans);
} else if (ans == 4) {
let fans = +x / +y;
console.log("Your answer is " + fans);
} else {
console.log("Incorrect operation!!!");
}
}
function faulty_calc(x, y) {
let ans = prompt(
"Which operation do you like to perform?
1)Add
2)Subtract
3)Multiplication
4)Division"
);
if (ans == 1) {
let fans = +x - +y;
console.log("Your answer is " + fans);
} else if (ans == 2) {
let fans = +x / +y;
console.log("Your answer is " + fans);
} else if (ans == 3) {
let fans = +x + +y;
console.log("Your answer is " + fans);
} else if (ans == 4) {
let fans = +x / +y;
console.log("Your answer is " + fans);
} else {
console.log("Incorrect operation!!!");
}
}
var ques = prompt("do you want to perform another operation?
1)yes
2)no");
} while (ques == 1);
Challenge accepted Harry Bhai
This is code:
let a = Number(prompt("Enter the first number:"));
let b = Number(prompt("Enter the second number:"))
let random = Math.random();
let addition = a + b;
let subtraction = a - b;
let multiplication = a * b;
let division = a / b;
let Exponention = a ** b;
if (random < 0.1) {
console.log("addition calculation:", a - b);
console.log("subtraction calculation:", a / b);
console.log("multiplication calculation:", a + b);
console.log("division calculation:", a * b);
console.log("Exponention calculation:", a ** b);
} else {
console.log("addition calculation:", a + b);
console.log("subtraction calculation:", a - b);
console.log("multiplication calculation:", a * b);
console.log("division calculation:", a / b);
console.log("exponentiation calculation:", a ** b);
}
this is the best course
here i multiply math random into ten so it genrates random number between 1 to 10
let x = Math.random()*10
console.log(x) // this line is only for checking random numbers are generating properly or not
let inp1 = 4
let inp2 = 6
let op = "+"
if(x
let a = parseInt(prompt('Enter first number :'))
let b = parseInt(prompt('Enter second number :'))
console.log(a,b)
let randInt = Math.floor(Math.random() * 100);
console.log(randInt)
function FaultyCalc(firstnumber, secondnumber) {
console.log('Addition of the first and second number is ' + (a-b) )
console.log('Multiplication of the first and second number is ' + (a+b) )
console.log('Subtraction of the first and second number is ' + (a/b) )
console.log('Division of the first and second number is ' + (a**b) )
}
function TruelyCalc(firstnumber, secondnumber) {
console.log('Addition of the first and second number is ' + (a+b) )
console.log('Multiplication of the first and second number is ' + (a*b) )
console.log('Subtraction of the first and second number is ' + (a-b) )
console.log('Division of the first and second number is ' + (a/b) )
}
if(randInt
Congratulations for 5M in advance ❤🎉
Users Input kaise lete hai Is par bhi ek Video Banye @CodeWithHarry
done
// craete a faulty calculator using javsscript
let a = parseInt(prompt("enter the first number"));
let b = parseInt(prompt("enter the second number"));
let random = Math.random();
let addition = a+b;
let subtractiom = a-b;
let multiplication = a*b;
let division = a/b;
if(random < 0.1){
console.log("addition calculation:",a-b);
console.log("subtraction calculation:",a+b);
console.log("multiplication calculation:",a/b);
console.log("division calculation:",a*b);
}
else {
console.log("addition calculation:",a+b);
console.log("subtraction calculation:",a-b);
console.log("multiplication calculation:",a*b);
console.log("division calculation:",a/b);
}
challenge accepted harry bhai
#solution
function faultyCalculator(operator, operand1, operand2) {
const operators = {
"+": (a, b) => a - b,
"-": (a, b) => a / b,
"*": (a, b) => a + b,
"/": (a, b) => a ** b,
};
// check the operator is valid
if (!operators[operator]) {
return "Invalid operator";
}
// Perform the calculation
let result;
if (Math.random() < 0.1) {
result = Math.random() * 1000;
} else {
result = operators[operator](operand1, operand2);
}
return result;
}
const operator = '*';
const operand1 = 5;
const operand2 = 3;
const result = faultyCalculator(operator, operand1, operand2);
console.log(result);
// Function to perform faulty calculations
function faultyCalculator(operator, num1, num2) {
let result;
// Check the operator and perform the corresponding operation
if (operator === '+') {
result = num1 - num2; // Faulty addition
} else if (operator === '-') {
result = num1 + num2; // Faulty subtraction
} else if (operator === '*') {
result = num1 / num2; // Faulty multiplication
} else if (operator === '/') {
result = num1 * num2; // Faulty division
} else {
return "Invalid operator";
}
return result;
}
// Example usage
var operator = '+';
var num1 = 5;
var num2 = 3;
var result = faultyCalculator(operator, num1, num2);
console.log(`${num1} ${operator} ${num2} = ${result}`);
var operator = '-';
var num1 = 5;
var num2 = 3;
var result = faultyCalculator(operator, num1, num2);
console.log(`${num1} ${operator} ${num2} = ${result}`);
var operator = '*';
var num1 = 5;
var num2 = 3;
var result = faultyCalculator(operator, num1, num2);
console.log(`${num1} ${operator} ${num2} = ${result}`);
var operator = '/';
var num1 = 5;
var num2 = 3;
var result = faultyCalculator(operator, num1, num2);
console.log(`${num1} ${operator} ${num2} = ${result}`);
#HarryBhai done Exercise 9 just taken some extra help as I was getting error again and again
// Faulty Calculator
console.log("Welcome to Faulty Calculator")
if (Math.random() < 0.1) {
function sum(a, b) {
return (a - b)
}
function subtraction(a, b) {
return (a / b)
}
function multiplication(a, b) {
return (a + b)
}
function divide(a, b) {
return (a ** b)
}
}
else {
function sum(a, b) {
return (a + b)
}
function subtraction(a, b) {
return (a - b)
}
function multiplication(a, b) {
return (a * b)
}
function divide(a, b) {
return (a / b)
}
}
let q = sum(2, 3)
let r = subtraction(5, 3)
let s = multiplication(10, 8)
let t = divide(30, 4)
console.log(q)
console.log(r)
console.log(s)
console.log(t)
Pre congratulations for 5m🎉
Sigma Batch Op❤❤❤❤❤
#Challenge accepted
#SigmaBatchOp
Loving the course
Sigma Batch OP
#day5 well! Challenge accepted even executed.
jald hi pahuchunga yaha tak😉
Congratulations for 5M🎉🎉🎉🎉🎉❤❤❤❤❤❤❤ Lots Of Love #sigma
Sir ek video aap website se pesha kesha aata hai kitna aata hai iss completely information de di please sir kitna views pr kitna milta hai all detiall
Challange accepted
harry vai, i can't understand the using of Math.random() in this faulty calculator
faulty calculator code here:
let a = prompt("enter the value of a:")
let operators = prompt("enter the operator:")
let b = prompt("enter the value of b:")
a = parseInt(a)
b = parseInt(b)
const addInverse = (a, b) => {
return a - b
}
const multiplyInverse = (a, b) => {
return a + b
}
const divideInverse = (a, b) => {
return a ** b
}
const substractInverse = (a, b) => {
return a / b
}
if(operators == '+'){
console.log(addInverse(a, b))
}
else if(operators == '*'){
console.log(multiplyInverse(a, b))
}
else if(operators == '/'){
console.log(divideInverse(a, b))
}
else if(operators == '-'){
console.log(substractInverse(a, b))
}
else{
console.log('invalid input')
}
challenge accepted and the answer is
let num1 = prompt("Please enter the number1"); num1=num1*1;
let num2 = prompt("Please enter the number2");num2=num2*1;
let operator = prompt("Please enter the operator");
if (Math.random()>0.1){
if (operator == "+" ){
alert(num1+num2);
}
else if (operator == "-" ){
alert(num1-num2);
}
else if (operator == "*" ){
alert(num1*num2);
}
else if (operator == "/" ){
alert(num1/num2);
}
}
else {
if (operator == "+" ){
alert(num1-num2);
}
else if (operator == "-" ){
alert(num1/num2);
}
else if (operator == "*" ){
alert(num1+num2);
}
else if (operator == "/" ){
alert(num1**num2);
}
}
please tell ne if this is correct or not..???
Sigma Batch OP ❤
Challenge accepted!
let num1 = prompt("Enter first number");
num1 = Number.parseInt(num1);
let num2 = prompt("Enter second number:");
num2 = Number.parseInt(num2);
let rand = Math.random();
if (rand < 0.1) {
console.log("Addition is:" + num1 - num2);
console.log("Multiplication is:" + num1 + num2);
console.log("Subtraction is:" + num1 / num2);
console.log("division is:" + num1 ** num2);
}
else {
console.log("Addition is:" + num1 +num2);
console.log("Multiplication is:" + num1 * num2);
console.log("Subtraction is:" + num1 - num2);
console.log("division is:" + num1 / num2);
}
Users Input kaise lete hai Is par bhi ek Video Banye @codewithharry
Thank you for course it is very good.
function faultycal(a,b,op){
switch(op)
{
case '+': console.log(a-b); break;
case '-': console.log(a+b); break;
case '*': console.log(a/b); break;
case '/': console.log(a*b); break;
}
}
function normalcal(a,b,op){
switch(op)
{
case '+': console.log(a+b); break;
case '-': console.log(a-b); break;
case '*': console.log(a*b); break;
case '/': console.log(a/b); break;
}
}
let a=10;
let b=10;
let op='+';
let isfaulty=Math.random();
if(isfaulty
challenge done sirrr
Amazing Bhai
If anybody got time, I suggest turning on the caption at 4:16 you might see something interesting.
Sir sir sir !!!!! IMPORTANT QUESTION ❓ Kia AI programmers ki jagah lelega ??
Sir please answer me 😨🙏 !!! Please 😭
❤️ ❤️
challenge accepted :
let A = Math.random();
const faulty1 = (a, b) => {
if (A < 0.1) {
return a - b;
}
else {
return a + b;
}
}
let addition = faulty1(2, 3);
console.log("The addition of two numbers is:", addition);
const faulty2 = (a, b) => {
if (A < 0.1) {
return a / b;
}
else {
return a - b;
}
}
let substraction = faulty2(9, 3);
console.log("The substraction of two numbers is:", substraction);
const faulty3 = (a, b) => {
if (A < 0.1) {
return a + b;
}
else {
return a * b;
}
}
let Multiplication = faulty3(3, 4);
console.log("The multiplication of the two numbers is:", Multiplication);
const faulty4 = (a, b) => {
if (A < 0.1) {
return a ** b;
}
else {
return a / b;
}
}
let Division = faulty4(3, 4);
console.log("The multiplication of the two numbers is:", Division);
Please explain about the 10 percentage thing again. I didn't get that. Thank u
#Challengeaccepted very nice harry bhaiya
// A faulty calculator which shows incorrect calc at 10% of calculations
let a = 5;
let b = 2;
if(Math.random()
function faultycalc(a, b, c) {
let x = Math.random();
if (x < 0.1) {
switch (c) {
case 1:
substraction(a, b);
break;
case 2:
divide(a, b);
break;
case 3:
add(a, b);
break;
case 4:
exponent(a, b);
break;
default: console.log("Invalid Input");
break;
}
}
else {
switch (c) {
case 1:
add(a, b);
break;
case 2:
substraction(a, b);
break;
case 3:
multiply(a, b);
break;
case 4:
divide(a, b);
break;
default: console.log("Invalid Input");
break;
}
}
}
function add(a, b) {
console.log(a + b);
}
function substraction(a, b) {
console.log(a - b);
}
function multiply(a, b) {
console.log(a * b);
}
function divide(a, b) {
console.log(a / b);
}
function exponent(a, b) {
console.log(a ** b);
}
faultycalc(5, 3, 1);
faultycalc(5, 3, 2);
faultycalc(5, 3, 3);
faultycalc(5, 3, 4);
faultycalc(5, 3, 5);