Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 928e2a3

Browse files
problme 69 complete
1 parent 363be60 commit 928e2a3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎problme69/problme69.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,31 @@ Implement a simple JavaScript calculator. The calculator should take two numbers
44
55
66
*/
7+
8+
const JsCalculator = (num1, num2, operator) => {
9+
10+
if( operator === '+'){
11+
return num1 + num2 ;
12+
}
13+
else if( operator === '-'){
14+
return num1 - num2;
15+
}
16+
else if( operator === '*'){
17+
return num1 * num2;
18+
}
19+
else if( operator === '/'){
20+
if (num2 === 0) {
21+
return "Error: Division by zero is not allowed.";
22+
}
23+
return num1 / num2 ;
24+
}
25+
else if ( operator === '%'){
26+
return num1 % num2 ;
27+
}
28+
else{
29+
return 'Error: Please inter valid number and mathematical operator.';
30+
}
31+
};
32+
33+
const result = JsCalculator(400, 200, '+');
34+
console.log(result);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /