diff --git a/img/Star 2.png b/img/Star 2.png new file mode 100644 index 0000000..db3c82c Binary files /dev/null and b/img/Star 2.png differ diff --git a/index.html b/index.html index 752cd12..c55fb2c 100644 --- a/index.html +++ b/index.html @@ -25,12 +25,18 @@

Поехали! -
-
ВИКТОРИНА
-
УГАДАЙ ЧИСЛО
-
ПЕРЕВЕРНИ ТЕКСТ
-
ПРОСТАЯ АРИФМЕТИКА
-
+
+
+
ВИКТОРИНА
+
УГАДАЙ ЧИСЛО
+
ПЕРЕВЕРНИ ТЕКСТ
+
ПРОСТАЯ АРИФМЕТИКА
+
ВИКТОРИНА
+
УГАДАЙ ЧИСЛО
+
ПЕРЕВЕРНИ ТЕКСТ
+
ПРОСТАЯ АРИФМЕТИКА
+
+
@@ -144,14 +150,14 @@

Угадай число

- game

Простая арифметика

Решай примеры на сложение, вычитание, умножение и деление

- +
+ game
@@ -161,21 +167,21 @@

Переверни текст

Введи текст и получи его в обратном порядке

- + game
- game

Викторина

Проверь свои знания в разных областях

- +
+ game
@@ -185,22 +191,22 @@

Камень, ножницы, бумага

Сыграй в классическую игру против компьютера

- + game
- game
-

Генератор случайных чисел

+

Генератор случайного цвета

Игра, в которой при клике на кнопку фон страницы меняется на случайный.

- +
+ game
diff --git a/script.js b/script.js index cdddbbc..9c8d0ed 100644 --- a/script.js +++ b/script.js @@ -34,6 +34,47 @@ function startGameOne() { } } +function startMathGame() { + let num1, num2, operation, question, correctAnswer; + + let operations = ["+", "-", "*", "/"]; + operation = operations[Math.floor(Math.random() * operations.length)]; + + if (operation === "/") { + num2 = Math.floor(Math.random() * 19) + 1; + correctAnswer = Math.floor(Math.random() * 10) + 1; + num1 = num2 * correctAnswer; + } else { + num1 = Math.floor(Math.random() * 20) + 1; + num2 = Math.floor(Math.random() * 20) + 1; + switch (operation) { + case "+": + correctAnswer = num1 + num2; + break; + case "-": + correctAnswer = num1 - num2; + break; + case "*": + correctAnswer = num1 * num2; + break; + } + } + + question = `${num1} ${operation} ${num2}`; + + + let userAnswer = prompt(`Реши пример: ${question}`); + + if (Number(userAnswer) === correctAnswer) { + alert("Верно!"); + } else { + alert(`Ошибка! Правильный ответ: ${correctAnswer}`); + } +} + + + + // Игра "Камень, ножницы, бумага" const playGameRockPaperScissors = () => { const choices = ["камень", "ножницы", "бумага"]; @@ -71,4 +112,96 @@ function startGameOne() { alert(`Ваш выбор: ${userChoice}\nВыбор компьютера: ${computerChoice}\nРезультат: ${result}`); }; - \ No newline at end of file + + function startReverseTextGame() { + let userText = prompt("Введите текст, который нужно перевернуть:"); + + if (userText !== null) { + let reversed = userText.split("").reverse().join(""); + + alert("Перевернутый текст: " + reversed); + } +} + + +function startQuizGame() { + const quiz = [ + { + question: "Какой цвет небо?", + options: ["1. Красный", "2. Синий", "3. Зеленый"], + correctAnswer: 2 + }, + { + question: "Сколько дней в неделе?", + options: ["1. Шесть", "2. Семь", "3. Восемь"], + correctAnswer: 2 + }, + { + question: "Сколько у человека пальцев на одной руке?", + options: ["1. Четыре", "2. Пять", "3. Шесть"], + correctAnswer: 2 + } + ]; + + let score = 0; + + for (let i = 0; i < quiz.length; i++) { + let q = quiz[i]; + let userAnswer = prompt(q.question + "\n" + q.options.join("\n")); + + if (Number(userAnswer) === q.correctAnswer) { + score++; + } + } + + alert("Вы ответили правильно на " + score + " из " + quiz.length + " вопросов!"); +} + +function playRockPaperScissors() { + const options = ["камень", "ножницы", "бумага"]; + + let userChoice = prompt("Выберите: камень, ножницы или бумага").toLowerCase(); + + if (!options.includes(userChoice)) { + alert("Ошибка! Нужно ввести: камень, ножницы или бумага."); + return; + } + + let computerChoice = options[Math.floor(Math.random() * options.length)]; + + let result = ""; + + if (userChoice === computerChoice) { + result = "Ничья!"; + } else if ( + (userChoice === "камень" && computerChoice === "ножницы") || + (userChoice === "ножницы" && computerChoice === "бумага") || + (userChoice === "бумага" && computerChoice === "камень") + ) { + result = "Вы выиграли! 🎉"; + } else { + result = "Вы проиграли 😢"; + } + + alert( + "Ваш выбор: " + userChoice + + "\nВыбор компьютера: " + computerChoice + + "\nРезультат: " + result + ); +} + + +function startRandomColorGame() { + const letters = "0123456789ABCDEF"; + let color = "#"; + for (let i = 0; i < 6; i++) { + color += letters[Math.floor(Math.random() * 16)]; + } + const sections = document.querySelectorAll(".about-games, .mini-games"); + sections.forEach(section => { + section.style.backgroundColor = color; + }); + + alert("Новый случайный цвет: " + color); +} + diff --git a/styles.css b/styles.css index 6f330b0..f3e0867 100644 --- a/styles.css +++ b/styles.css @@ -83,6 +83,21 @@ html { align-items: center; } +.bottom-line__wrapper { + display: flex; + gap: 60px; + animation: scroll-left 15s linear infinite; +} + +@keyframes scroll-left { + 0% { + transform: translateX(0); + } + 100% { + transform: translateX(-50%); + } +} + .bottom-line__games:not(:last-child)::after { content: url(img/Star.svg); display: inline-block; @@ -109,17 +124,20 @@ html { margin: 0; } -.about-games { - background-image: url(img/aboutgames-background.jpg); - background-size: cover; - background-position: center; - background-repeat: no-repeat; +.about-games, +.mini-games { + background-color: rgba(32, 32, 39, 1); + background-image: url("img/Star 2.png"), url("img/Star 1.png"); + background-repeat: no-repeat, no-repeat; + background-position: bottom 100px left 50px, top 50px right 50px; + background-size: 120px, 300px; width: 100%; margin: 0 auto; padding: 40px; box-sizing: border-box; } + .about-games__title { color: rgb(255, 255, 255); display: flex; @@ -286,12 +304,6 @@ html { padding: 32px; } -.mini-games { - background-color: #202027; - width: 100%; - margin: 0 auto; -} - /* Контейнер для карточек игр */ .mini-games__container { display: flex; @@ -445,22 +457,33 @@ html { margin-left: 0 !important; align-self: center; } - .bottom-line { - position: absolute; - bottom: 0; - left: 0; - top: auto; - height: 51px; - padding: 0 20px; - justify-content: center; - align-items: center; - font-size: 24px; - overflow: hidden; - } - .bottom-line__games:not(:last-child)::after { - margin: 30px; +.bottom-line { + position: absolute; + bottom: 0; + left: 0; + width: 100%; + height: 51px; + padding: 0 20px; + font-size: 24px; + overflow: hidden; + background: rgb(188, 236, 48); +} + +.bottom-line__wrapper { + display: flex; + gap: 60px; + animation: scroll-left 15s linear infinite; +} + +@keyframes scroll-left { + 0% { + transform: translateX(0); } + 100% { + transform: translateX(-50%); + } +} } /* Мобильные устройства*/ diff --git a/tasks.html b/tasks.html new file mode 100644 index 0000000..caba061 --- /dev/null +++ b/tasks.html @@ -0,0 +1,60 @@ + + + + + + Document + + + + + + + + + + Document + + + +

Это заголовок!

+ + + +

Это абзац текста.

+ + + + +

Это заголовок!

+ + + + +

Это описание 1

+

Это описание 2

+

Это описание 3

+ + + +

Описание 1

+

Просто абзац

+

Описание 2

+

Примечание

+

Описание 3

+ + + + + +

Описание 1

+

Просто абзац

+

Описание 2

+

Описание 3

+ + + + + + + diff --git a/tasks.js b/tasks.js index fd66bb6..e47a47a 100644 --- a/tasks.js +++ b/tasks.js @@ -1,77 +1,66 @@ // Задание 1 -const people = [ - { name: 'Глеб', age: 29 }, - { name: 'Анна', age: 17 }, - { name: 'Олег', age: 7 }, - { name: 'Оксана', age: 47 } - ]; - - console.log(people.sort((a, b) => a.age - b.age)); +const title = document.querySelector("#main-title"); +const button = document.querySelector("#toggle-btn"); + +button.addEventListener("click", () => { + if (title.style.display === "none") { + title.style.display = "block"; + button.textContent = "Скрыть"; + } else { + title.style.display = "none"; + button.textContent = "Показать"; + } +}); + // Задание 2 -function isPositive(num) { - return num > 0; -} - -function isMale(person) { - return person.gender === 'male'; -} - -function filter(array, ruleFunction) { - const result = []; - - for (let i = 0; i < array.length; i++) { - if (ruleFunction(array[i])) { - result.push(array[i]); - } - } - - return result; -} - -console.log(filter([3, -4, 1, 9], isPositive)); // [3, 1, 9] - -const people = [ - {name: 'Глеб', gender: 'male'}, - {name: 'Анна', gender: 'female'}, - {name: 'Олег', gender: 'male'}, - {name: 'Оксана', gender: 'female'} -]; - -console.log(filter(people, isMale)); +const text = document.querySelector("#my-text"); +const button_two = document.querySelector("#color-btn"); -// Задание 3 -const intervalId = setInterval(() => { - console.log(new Date()); -}, 3000); +button_two.addEventListener("click", () => { + text.style.color = "blue"; +}); -setTimeout(() => { - clearInterval(intervalId); - console.log('30 секунд прошло'); -}, 30000); +// Задание 3 +const title_two = document.querySelector("#main-title_two"); +const changeTextBtn = document.querySelector("#change-text-btn"); +changeTextBtn.addEventListener("click", () => { + title_two.textContent = "Привет, мир!"; +}); // Задание 4 -function delayForSecond(callback) { - setTimeout(callback, 1000); -} +const descriptions = document.querySelectorAll(".description"); -delayForSecond(function () { - console.log('Привет, Глеб!'); +descriptions.forEach(el => { + el.textContent = "Измененный текст"; }); - // Задание 5 -function delayForSecond(cb) { - setTimeout(() => { - console.log('Прошла одна секунда'); - if(cb) { cb(); } - }, 1000) -} +const descriptions1 = document.querySelectorAll(".description1"); +descriptions1.forEach(element => { + element.textContent = "Новый текст"; +}); + +// Задание 6 +const addBtn = document.querySelector("#add-btn"); -function sayHi (name) { - console.log(`Привет, ${name}!`); -} +addBtn.addEventListener("click", () => { + const newParagraph = document.createElement("p"); + newParagraph.textContent = "Новый абзац"; + + document.body.appendChild(newParagraph); +}); -delayForSecond(() => sayHi('Глеб')); + +// Задание 7 +const deleteBtn = document.querySelector("#delete-btn"); + +deleteBtn.addEventListener("click", () => { + const firstDescription = document.querySelector(".description-three"); + + if (firstDescription) { + firstDescription.remove(); + } +});