diff --git a/homeworks/artem.sokur_Grimdvl/4-basics/basics.js b/homeworks/artem.sokur_Grimdvl/4-basics/basics.js new file mode 100644 index 00000000..c84214b0 --- /dev/null +++ b/homeworks/artem.sokur_Grimdvl/4-basics/basics.js @@ -0,0 +1,29 @@ +const firstNumber = +prompt('Enter the first number:', '').trim(); +const sign = prompt('Enter mathematic sign (+, -, *, /, %, **):', '').trim(); +const secondNumber = +prompt('Enter the second number:', '').trim(); + +function calculator() { + let result; + + if (sign === '+') { + result = firstNumber + secondNumber; + } else if (sign === '-') { + result = firstNumber - secondNumber; + } else if (sign === '*') { + result = firstNumber * secondNumber; + } else if (sign === '/') { + result = firstNumber / secondNumber; + } else if (sign === '%') { + result = firstNumber % secondNumber; + } else if (sign === '**') { + result = firstNumber ** secondNumber; + } else { + result = 'Ups! Something went wrong...'; + } + + return result; +} +const equal = calculator(); + +alert(`Your result: ${Number.isNaN(equal) || equal === undefined || equal === '' ? 'Ups! Something went wrong...' : equal}`); +window.location.reload(); diff --git a/homeworks/artem.sokur_Grimdvl/4-basics/index.html b/homeworks/artem.sokur_Grimdvl/4-basics/index.html new file mode 100644 index 00000000..fe71363a --- /dev/null +++ b/homeworks/artem.sokur_Grimdvl/4-basics/index.html @@ -0,0 +1,11 @@ + + + + + + Calculator + + + + + \ No newline at end of file