-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |