Skip to content

Commit

Permalink
Merge pull request #199 from MastersAcademy/4-js_basics_Grimdvl
Browse files Browse the repository at this point in the history
lesson_5
  • Loading branch information
vadym-zinchenko-moc authored Oct 27, 2023
2 parents 858d471 + 2d2358a commit 367e73e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
29 changes: 29 additions & 0 deletions homeworks/artem.sokur_Grimdvl/4-basics/basics.js
Original file line number Diff line number Diff line change
@@ -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();
11 changes: 11 additions & 0 deletions homeworks/artem.sokur_Grimdvl/4-basics/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>Calculator</title>
</head>
<body>
<script src="basics.js"></script>
</body>
</html>

0 comments on commit 367e73e

Please sign in to comment.