Created
May 6, 2025 19:57
-
-
Save GhostRJY/ad66fc480f597a7c5690b1ec6da27007 to your computer and use it in GitHub Desktop.
первый раз с javascript !)
This file contains hidden or 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
index.html | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<script type="text/javascript" src=".\\app.js"></script> | |
<title>My First Project</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 0; | |
padding: 0; | |
background-color: #f4f4f4; | |
} | |
header { | |
background: #333; | |
color: #fff; | |
padding: 1rem 0; | |
text-align: center; | |
} | |
main { | |
padding: 2rem; | |
text-align: center; | |
} | |
footer { | |
background: #333; | |
color: #fff; | |
text-align: center; | |
padding: 1rem 0; | |
position: fixed; | |
bottom: 0; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<h1>Welcome to My Website</h1> | |
</header> | |
<main> | |
<p>This is a simple standard website layout.</p> | |
<button onclick="askUser()">Click Me!</button> | |
<!-- <script> | |
function plus1() { | |
let counter = 0; | |
counter++; | |
alert("Counter: " + counter); | |
} | |
</script> --> | |
</main> | |
<footer> | |
<p>© 2025 My First Project</p> | |
</footer> | |
</body> | |
</html> | |
app.js | |
function askUser() { | |
let a = prompt("Введите число:"); | |
let b = prompt("Введите степень числа:"); | |
let c = degreeNumber(a, b); | |
alert(a + " в степени " + b + " равно " + c); | |
c = avg(a, b); | |
alert("среднеарифметическое" + a + " и " + b + " равно " + c); | |
a = prompt("Введите число:"); | |
c = square(a); | |
alert("квадрат числа " + a + " равен " + c); | |
a = prompt("Введите расстояние в километрах:"); | |
c = kmToMile(a); | |
alert("Расстояние в милях: " + c); | |
calculate(); | |
timeLeft(); | |
getSecondDigit(); | |
digitsToLeft(); | |
askBornYear(); | |
let radius = prompt("Введите радиус круга:"); | |
let area = circleArea(radius); | |
alert("Площадь круга с радиусом " + radius + " равна " + area); | |
alert(isEven()); | |
} | |
function degreeNumber(a, b) { | |
return Math.pow(a, b); | |
} | |
function avg(a, b) { | |
return (Number(a) + Number(b)) / 2; | |
} | |
function square(a) { | |
return a * a; | |
} | |
function kmToMile(km) { | |
return km * 0.621371; | |
} | |
function calculate() { | |
let a = prompt("Введите первое число:"); | |
let b = prompt("Введите второе число:"); | |
let c = Number(a) + Number(b); | |
alert("Сумма чисел " + a + " и " + b + " равна " + c); | |
c = a - b; | |
alert("Разность чисел " + a + " и " + b + " равна " + c); | |
c = a * b; | |
alert("Произведение чисел " + a + " и " + b + " равно " + c); | |
c = a / b; | |
if (b != 0) { | |
alert("Частное чисел " + a + " и " + b + " равно " + c); | |
} else { | |
alert("На ноль делить нельзя!"); | |
} | |
} | |
function timeLeft() { | |
let hours = prompt("Введите текущий час:"); | |
let minutes = prompt("Введите текущие минуты:"); | |
let forTommorowHours = 24 - Number(hours); | |
let forTommorowMinutes = 60 - Number(minutes); | |
if (forTommorowMinutes > 0) { | |
--forTommorowHours; | |
} | |
alert( | |
"Осталось до завтра " + | |
forTommorowHours + | |
" часа и " + | |
forTommorowMinutes + | |
" минут." | |
); | |
} | |
function getSecondDigit() { | |
let number = prompt("Введите трёхзначное число:"); | |
if (number.length == 3) { | |
// Получаем вторую цифру | |
let secondDigit = number[1]; | |
alert("Вторая цифра числа: " + secondDigit); | |
} else { | |
alert("Вводи трёхзначное число!!!"); | |
} | |
} | |
function digitsToLeft() { | |
let number = prompt("Введите число:"); | |
if (number.length > 1) { | |
//slice возвращаю число без первой цифры добавляю первую цифру в конец | |
let shiftedNumber = number.slice(1) + number[0]; | |
alert("Число после сдвига: " + shiftedNumber); | |
} else { | |
alert("Вводи число с большим количеством цифр!!!"); | |
} | |
} | |
function askName() { | |
let name = prompt("Как тебя зовут?"); | |
alert("Привет, " + name + "!"); | |
} | |
function askBornYear() { | |
let bornYear = prompt("Твой год рождения?"); | |
let age = 2025 - bornYear; | |
alert("Тебе " + age + " лет!"); | |
} | |
function circleArea(radius) { | |
return Math.PI * radius * radius; | |
} | |
function chockolateProMoney() { | |
let chockolatePrice = 2.5; | |
let money = prompt("Сколько у вас денег?"); | |
// округляем до целого числа | |
let chockolateCount = Math.floor(money / chockolatePrice); | |
alert("Вы можете купить " + chockolateCount + " шоколадок."); | |
} | |
function isEven() { | |
let number = prompt("Введите число:"); | |
return number % 2 == 0 ? "Число четное" : "Число нечетное"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment