Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 6 #906

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
.DS_Store
HomeWorkAnswers/.DS_Store
Binary file added HomeWorkAnswers/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions HomeWorkAnswers/Lesson 2/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Display current date</title>
</head>
<body>
<p id="output">New date</p>
<button id="btn">Click me!</button>
<script>
document.querySelector("#btn").onclick = function () {
let output = document.querySelector("#output");
output.innerHTML = new Date();
output.style.color = "red";
};
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions HomeWorkAnswers/Lesson 2/task3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Say hello</title>
</head>
<body>
<p id="output">Текст привітання</p>
<button id="btn">Скажи привіт</button>
<script>
document.querySelector("#btn").onclick = function () {
let name = "Надія";
let output = document.querySelector("#output");
output.innerHTML = `Привіт, ${name}!`;
output.style.color = "blue";
};
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions HomeWorkAnswers/Lesson 3/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let input = prompt("Введіть число:");
number = Number(input);
if (isNaN(number)) {
alert("Введене значення не є числом. Спробуйте ще раз.");
} else {
if (number % 2 === 0) {
alert("Число " + number + " є парним.");
} else {
alert("Число " + number + " є непарним.");
}
}
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions HomeWorkAnswers/Lesson 3/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let currentDate = new Date();
let dayOfWeek = currentDate.getDay();
let dayName;
if (dayOfWeek === 0) {
dayName = "Сьогодні неділя";
} else if (dayOfWeek === 1) {
dayName = "Сьогодні понеділок";
} else if (dayOfWeek === 2) {
dayName = "Сьогодні вівторок";
} else if (dayOfWeek === 3) {
dayName = "Сьогодні середа";
} else if (dayOfWeek === 4) {
dayName = "Сьогодні четвер";
} else if (dayOfWeek === 5) {
dayName = "Сьогодні п'ятниця";
} else if (dayOfWeek === 6) {
dayName = "Сьогодні субота";
}
alert(dayName);
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions HomeWorkAnswers/Lesson 3/task3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let input = prompt("Введіть рік:");
year = Number(input);
if (isNaN(year) && year >= 0) {
alert("Введене значення не є роком. Спробуйте ще раз.");
} else {
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
alert(year + " є високосним роком.");
} else {
alert(year + " не є високосним роком.");
}
}
</script>
</body>
</html>
93 changes: 93 additions & 0 deletions HomeWorkAnswers/Lesson 4/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
let userScore = 0;
let computerScore = 0;
let rounds = 0;

function playGame() {
while (true) {
let computerChoice = Math.floor(Math.random() * 3) + 1;

function getValue(message) {
while (true) {
let value = prompt(message);
let isValid =
!isNaN(value) &&
value !== "" &&
value !== null &&
value >= 1 &&
value <= 4;
if (isValid) return Number(value);
}
}

let userChoice = getValue(
"Напишіть ваш вибір у вигляді цифр. Камінь - це 1. Папір - це 2. І ножниці - це 3. Або введіть цифру 4 для завершення гри"
);

if (userChoice === 4) {
alert(
`Гра завершена. Ви зіграли ${rounds} раундів. Рахунок: Ви - ${userScore}, Штучний інтелект - ${computerScore}`
);
break;
}

function getChoiceText(choice) {
switch (choice) {
case 1:
return "Камінь";
case 2:
return "Папір";
case 3:
return "Ножниці";
}
}
let userChoiceText = getChoiceText(userChoice);
let computerChoiceText = getChoiceText(computerChoice);

alert(
`Ви: ${userChoiceText}, Штучний інтелект: ${computerChoiceText}`
);

function determineWinner(userChoice, computerChoice) {
if (userChoice === computerChoice) {
alert("Це нічия!");
return "draw";
} else if (
(userChoice === 1 && computerChoice === 3) ||
(userChoice === 3 && computerChoice === 2) ||
(userChoice === 2 && computerChoice === 1)
) {
alert("Ви перемогли!");
return "user";
} else {
alert("Виграв штучний інтелект!");
return "computer";
}
}
let result = determineWinner(userChoice, computerChoice);
rounds++;

if (result === "user") {
userScore++;
} else if (result === "computer") {
computerScore++;
}

alert(
`Поточний рахунок: Ви - ${userScore}, Штучний інтелект - ${computerScore}`
);
}
}

playGame();
</script>
</body>
</html>
87 changes: 87 additions & 0 deletions HomeWorkAnswers/Lesson 4/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
function playGame() {
let correctCount = 0;
let incorrectCount = 0;
for (let i = 0; i < 5; i++) {
let operators = ["+", "-", "*", "/"];
let randomOperator =
operators[Math.floor(Math.random() * operators.length)];

let num1, num2;
if (randomOperator === "/") {
num2 = Math.floor(Math.random() * 9 + 1);
num1 = num2 * Math.floor(Math.random() * 10 + 1);
} else {
num1 = Math.floor(Math.random() * 100 + 1);
num2 = Math.floor(Math.random() * 100 + 1);
}

function getValue(message) {
while (true) {
let value = prompt(message);
let isValid = !isNaN(value) && value !== "";
if (isValid) return Number(value);
}
}

let correctAnswer;

switch (randomOperator) {
case "+":
correctAnswer = num1 + num2;
break;
case "-":
correctAnswer = num1 - num2;
break;
case "*":
correctAnswer = num1 * num2;
break;
case "/":
correctAnswer = num1 / num2;
break;
}

let attempts = 3;
let userAnswer;

while (attempts > 0) {
userAnswer = getValue(
`Напишіть цифрами правильну відповідь для математичного виразу: ${num1} ${randomOperator} ${num2}`
);

if (userAnswer === correctAnswer) {
alert("Правильна відповідь! Наступне завдання.");
correctCount++;
break;
} else {
attempts--;
incorrectCount++;
if (attempts > 0) {
alert(
`Неправильна відповідь! У вас залишилося ${attempts} спроби.`
);
} else {
alert(
`Неправильна відповідь! Правильна відповідь: ${correctAnswer}. Переходимо до наступного завдання.`
);
}
}
}
}
alert(
`Математичний квіз завершено! Правильні відповіді: ${correctCount}, Неправильні відповіді: ${incorrectCount}`
);
}

playGame();
</script>
</body>
</html>
40 changes: 40 additions & 0 deletions HomeWorkAnswers/Lesson 5/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
const height = getValue("Введіть вашу висоту в см:");
const weight = getValue("Введіть вашу вагу в кг:");

let calculationBMI = (weight, height) =>
Math.round((weight / Math.pow(height / 100, 2)) * 100) / 100;

let checkingBMI = (bmi) => {
alert(
`Ваш ІМТ ${bmi}. У вас ${
bmi < 18.5
? "недостатня вага"
: bmi < 24.9
? "нормальна вага"
: bmi < 29.9
? "надмірна вага"
: "ожиріння"
}.`
);
};

checkingBMI(calculationBMI(weight, height));

function getValue(message) {
while (true) {
let value = prompt(message);
if (!isNaN(value) && value > 0) return Number(value);
}
}
</script>
</body>
</html>
Loading