From ba68c54de272a07a10e66991de0b0af8fe741b8a Mon Sep 17 00:00:00 2001 From: KateDanKo Date: Thu, 14 Aug 2025 14:56:15 +0300 Subject: [PATCH 1/2] Update script.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit написала код --- script.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/script.js b/script.js index 4e2ff72..e2e7884 100644 --- a/script.js +++ b/script.js @@ -13,3 +13,45 @@ /* При генерации нового предсказания старое предсказание должно добавляться в начало списка «Мои предсказания» — .forecasts */ /* Для добавления предсказания в список воспользуйся шаблоном forecast-item */ + +const forecastButton = document.querySelector('.forecast-btn'); +const currentForecastTitle = document.querySelector('.current-forecast h1'); +const currentForecastProbability = document.querySelector('.current-forecast p'); + +function generateRandomNumber() { + return Math.floor(Math.random() * 5) + 1; +} + +function getPrediction(number) { + let prediction; + switch (number) { + case 1: + prediction = "Сегодня будет удачный день!"; + break; + case 2: + prediction = "Вам предстоит важное решение."; + break; + case 3: + prediction = "Ожидайте приятный сюрприз."; + break; + case 4: + prediction = "Ваши старания будут вознаграждены."; + break; + case 5: + prediction = "Будьте внимательны к своим близким."; + break; + default: + prediction = "Нет предсказания."; + } + return prediction; +} + +function generateForecast() { + const randomNumber = generateRandomNumber(); + const prediction = getPrediction(randomNumber); + + currentForecastTitle.textContent = prediction; + currentForecastProbability.textContent = `Сгенерированное число: ${randomNumber}`; +} + +forecastButton.addEventListener('click', generateForecast); From 858d1d0dce9bea4346aa774388da40a4bad0cb13 Mon Sep 17 00:00:00 2001 From: KateDanKo Date: Sat, 16 Aug 2025 11:30:37 +0300 Subject: [PATCH 2/2] Update script.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit все заново --- script.js | 85 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/script.js b/script.js index e2e7884..e14be07 100644 --- a/script.js +++ b/script.js @@ -14,44 +14,59 @@ /* Для добавления предсказания в список воспользуйся шаблоном forecast-item */ -const forecastButton = document.querySelector('.forecast-btn'); -const currentForecastTitle = document.querySelector('.current-forecast h1'); -const currentForecastProbability = document.querySelector('.current-forecast p'); -function generateRandomNumber() { - return Math.floor(Math.random() * 5) + 1; -} +const forecastBtn = document.querySelector('.forecast-btn'); +const currentForecast = document.querySelector('.current-forecast'); +const forecastsContainer = document.querySelector('.forecasts'); +const forecastTemplate = document.getElementById('forecast-item'); + -function getPrediction(number) { - let prediction; - switch (number) { - case 1: - prediction = "Сегодня будет удачный день!"; - break; - case 2: - prediction = "Вам предстоит важное решение."; - break; - case 3: - prediction = "Ожидайте приятный сюрприз."; - break; - case 4: - prediction = "Ваши старания будут вознаграждены."; - break; - case 5: - prediction = "Будьте внимательны к своим близким."; - break; - default: - prediction = "Нет предсказания."; - } - return prediction; +function getRandomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; } -function generateForecast() { - const randomNumber = generateRandomNumber(); - const prediction = getPrediction(randomNumber); - currentForecastTitle.textContent = prediction; - currentForecastProbability.textContent = `Сгенерированное число: ${randomNumber}`; -} +const predictions = [ + { + text: 'Удача на вашей стороне!', + probability: getRandomInt(50, 100) + }, + { + text: 'Вас ждут небольшие трудности.', + probability: getRandomInt(20, 50) + }, + { + text: 'Сегодня не лучший день для важных решений.', + probability: getRandomInt(0, 20) + }, + { + text: 'Вас ожидает приятное событие.', + probability: getRandomInt(60, 100) + }, + { + text: 'Будьте осторожны сегодня.', + probability: getRandomInt(10, 40) + } +]; + + +forecastBtn.addEventListener('click', () => { + + + const index = getRandomInt(0, predictions.length -1); + + const prediction = predictions[index]; + + + currentForecast.querySelector('h1').textContent = prediction.text; + currentForecast.querySelector('p').textContent = `Вероятность сбыться: ${prediction.probability}%`; + + + const forecastClone = forecastTemplate.content.cloneNode(true); + -forecastButton.addEventListener('click', generateForecast); + forecastClone.querySelector('h3').textContent = prediction.text; + + + forecastsContainer.insertBefore(forecastClone, forecastsContainer.firstChild); +});