Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mashutkat authored May 17, 2023
1 parent bb11394 commit 6558991
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
while(true) {
let a = prompt('Введите первое число (для выхода, нажмите "Отмена"):');
if (!a) {
alert('До свидания!');
break;
}
let b = prompt('Введите второе число:');
let operation = prompt('Введите знак операции (+, -, *, /):');
let result;

if (operation == '+') {
result = Number(a) + Number(b);
} else if (operation == '-') {
result = Number(a) - Number(b);
} else if (operation == '*') {
result = Number(a) * Number(b);
} else if (operation == '/') {
result = Number(a) / Number(b);
} else {
alert('Некорректный знак операции');
continue;
}

alert(`Результат: ${result}`);
}
50 changes: 50 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<title>Калькулятор на JavaScript</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Калькулятор на JavaScript</h1>
<form>
<label for="num1">Введите первое число:</label>
<input type="number" id="num1"/><br/><br/>

<label for="num2">Введите второе число:</label>
<input type="number" id="num2"/><br/><br/>

<label for="operator">Выберите операцию:</label>
<select id="operator">
<option selected value="+">Сложение</option>
<option value="-">Вычитание</option>
<option value="*">Умножение</option>
<option value="/">Деление</option>
</select><br/><br/>

<input type="button" value="Вычислить" onclick="calculate()"/>
</form>

<h2 id="result"></h2>

<script>
function calculate() {
let num1 = document.getElementById('num1').value;
let num2 = document.getElementById('num2').value;
let operator = document.getElementById('operator').value;
let result;

if (operator == '+') {
result = Number(num1) + Number(num2);
} else if (operator == '-') {
result = Number(num1) - Number(num2);
} else if (operator == '*') {
result = Number(num1) * Number(num2);
} else if (operator == '/') {
result = Number(num1) / Number(num2);
}

document.getElementById('result').innerHTML = `Результат: ${result}`;
}
</script>
</body>
</html>
50 changes: 50 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
body {
font-family: Arial, sans-serif;
}

h1 {
color: #1a1a1a;
}

form {
border: 2px solid #ccc;
padding: 20px;
width: 300px;
background-color: #f2f2f2;
border-radius: 5px;
}

label {
display: inline-block;
width: 150px;
font-weight: bold;
margin-bottom: 10px;
}

input[type="number"], select {
padding: 5px 10px;
margin-bottom: 15px;
width: 100%;
border: none;
border-radius: 4px;
box-sizing: border-box;
}

input[type="button"] {
background-color: #4CAF50;
color: white;
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type="button"]:hover {
background-color: #3e8e41;
}

h2 {
margin-top: 20px;
color: #4CAF50;
font-size: 1.5em;
}

0 comments on commit 6558991

Please sign in to comment.