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

Lesson5 #895

Open
wants to merge 19 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 4
}
13 changes: 13 additions & 0 deletions HomeWorkAnswers/Lesson2/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!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>
alert(new Date());
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions HomeWorkAnswers/Lesson2/task3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!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>
<button id="btn">Скажи привіт</button>
<script>
document.querySelector("#btn").onclick = function () {
let name = "Анастасія";
alert("Привіт " + name);
}
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions HomeWorkAnswers/Lesson3/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!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 numb = +prompt("Enter a number");
if (!isNaN(numb)) {
if (numb % 2 == 0) {
alert("Парне");
}
else {
alert("Непарне");
}
}
else {
alert("Error");
}
</script>
</body>
</html>
32 changes: 32 additions & 0 deletions HomeWorkAnswers/Lesson3/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!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 today = new Date().getDay();
switch (today) {
case 0: today = "Sunday";
break;
case 1: today = "Monday";
break;
case 2: today = "Tuesday";
break;
case 3: today = "Wednesday";
break;
case 4: today = "Thursday";
break;
case 5: today = "Friday";
break;
case 6: today = "Saturday";
break;
default: today = "Wrong day";
break;
}
alert(today);
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions HomeWorkAnswers/Lesson3/task3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!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 currentYear = +prompt("Enter the year");
if (!isNaN(currentYear)) {
if (currentYear % 4 == 0) {
alert("Високосний");
}
else {
alert("Невисокосний");
}
}

else {
alert("Wrong year");
}
</script>
</body>
</html>
56 changes: 56 additions & 0 deletions HomeWorkAnswers/Lesson4/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!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 userCounter = 0, compCounter = 0, counter = 0;
while (true) {
let userAnswer = prompt("Введіть 'камінь', 'ножиці' або 'папір'\nВведіть 'вихід' для закінчення гри").toLocaleLowerCase();
let compAnswer = Math.floor(Math.random() * 3) + 1;
let result;

if (userAnswer != "камінь" && userAnswer != "ножиці" && userAnswer != "папір" && userAnswer != "вихід") {
alert("Error");
continue;
}

if (userAnswer == "вихід") {
break;
}

switch (compAnswer) {
case 1:
compAnswer = "камінь";
break;
case 2:
compAnswer = "ножиці";
break;
case 3:
compAnswer = "папір";
break;
}

if (userAnswer == compAnswer) {
result = "Нічия!";
counter++;
} else if ((userAnswer == "камінь" && compAnswer == "ножиці") ||
(userAnswer == "ножиці" && compAnswer == "папір") ||
(userAnswer == "папір" && compAnswer == "камінь")) {
result = "Ви перемогли!";
userCounter++;
} else {
result = "Комп'ютер переміг!";
compCounter++;
}

alert(`Ваш вибір: ${userAnswer}\nВибір комп'ютера: ${compAnswer}\nРезультат гри: ${result}`)
}

alert(`Рахунок гри:\nВи: ${userCounter}\nКомп'ютер: ${compCounter}\nНічия: ${counter}`);
</script>
</body>
</html>
56 changes: 56 additions & 0 deletions HomeWorkAnswers/Lesson4/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!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 correctAnswer = 0;
let incorrectAnswer = 0;

for (let i = 0; i < 5; i++) {
let firstNumber = Math.floor(Math.random() * 10) + 1;
let secondNumber = Math.floor(Math.random() * 10) + 1;
let mathSymbol = Math.floor(Math.random() * 4) + 1;
let rightResult;

switch (mathSymbol) {
case 1:
mathSymbol = "+";
rightResult = firstNumber + secondNumber;
break;
case 2:
mathSymbol = "-";
rightResult = firstNumber - secondNumber;
break;
case 3:
mathSymbol = "*";
rightResult = firstNumber * secondNumber;
break;
case 4:
mathSymbol = "/";
rightResult = Math.floor(firstNumber / secondNumber);
break;
}

for (let j = 0; j < 3; j++) {
let result = +prompt(firstNumber + ' ' + mathSymbol + ' ' + secondNumber + ' =');

if (result == rightResult) {
alert("You are right!");
correctAnswer++;
break;
} else {
alert("Try again!");
incorrectAnswer++;
}
}
}

alert(`Правильні відповіді: ${correctAnswer}\nНеправильні відповіді: ${incorrectAnswer}`);

</script>
</body>
</html>
35 changes: 35 additions & 0 deletions HomeWorkAnswers/Lesson5/task1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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 imt(mass, height) {
let index = mass / (height * height) * 10000;
console.log(index);
return index;
}

function imtCategory(index) {
if (index < 18.5) {
alert("Недостатня вага");
} else if (index < 24.9 && index >= 18.5) {
alert("Нормальна вага");
} else if (index < 29.9 && index >= 24.9) {
alert("Надмірна вага");
} else if (index >= 30) {
alert("Ожиріння");
}
}

let massIndicator = +prompt("Введіть вагу");
let heightIndicator = +prompt("Введіть зріст");

imtResult = imt(massIndicator, heightIndicator);
imtCategory(imtResult);
</script>
</body>
</html>
51 changes: 51 additions & 0 deletions HomeWorkAnswers/Lesson5/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!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 circle(r) {
let p = 2 * 3.14 * r;
let s = 3.14 * r * r;
return alert(`Периметр: ${p}\nПлоща: ${s}`);
}

function rectangle(x, y) {
let p = 2 * (x + y);
let s = x * y;
return alert(`Периметр: ${p}\nПлоща: ${s}`);
}

function triangle(a, b, c) {
let p = a + b + c;
let s = Math.sqrt(p / 2 * (p / 2 - a) * (p / 2 - b) * (p / 2 - c));
return alert(`Периметр: ${p}\nПлоща: ${s}`);
}

let figure = prompt("Оберіть фігуру: коло, прямокутник, трикутник").toLowerCase();
switch (figure) {
case "коло":
let r = +prompt("Введіть радіус");
circle(r);
break;
case "прямокутник":
let x = +prompt("Введіть довжину");
let y = +prompt("Введіть ширину");
rectangle(x, y);
break;
case "трикутник":
let a = +prompt("Введіть першу сторону");
let b = +prompt("Введіть другу сторону");
let c = +prompt("Введіть третю сторону");
triangle(a, b, c);
break;
default:
alert("Error");
}

</script>
</body>
</html>