mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-25 22:10:43 -05:00
feat: basic js complete
This commit is contained in:
parent
e12e104518
commit
d58bef13a6
1 changed files with 37 additions and 0 deletions
37
calculator/js/script.js
Normal file
37
calculator/js/script.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
let firstNum = undefined
|
||||
let secondNum = undefined
|
||||
let operator = undefined
|
||||
|
||||
function add(x, y) {
|
||||
return Number(x + y);
|
||||
}
|
||||
|
||||
function subtract(x, y) {
|
||||
return x - y;
|
||||
}
|
||||
|
||||
function multiply(x, y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
function divive(x, y) {
|
||||
if (x === 0) {
|
||||
return 0
|
||||
} else if (y === 0) {
|
||||
alert("Cannot divide by 0!");
|
||||
}
|
||||
return x / y;
|
||||
}
|
||||
|
||||
function operate(firstNum, secondNum, operator) {
|
||||
switch (operator) {
|
||||
case '+':
|
||||
return add(firstNum, secondNum);
|
||||
case '-':
|
||||
return subtract(firstNum, secondNum);
|
||||
case '*':
|
||||
return multiply(firstNum, secondNum);
|
||||
case '/':
|
||||
return divive(firstNum, secondNum);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue