Skip to content
Open
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
39 changes: 39 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,42 @@
/* При генерации нового предсказания старое предсказание должно добавляться в начало списка «Мои предсказания» — .forecasts */

/* Для добавления предсказания в список воспользуйся шаблоном forecast-item */



const predictions = [
"Все будет супер!",
"Все будет еще лучше!",
"Затвра будет лучше, чем вчера!",
"Вскоре ты встретишь старого друга, и это будет замечательная встреча!",
"У тебя будет возможность реализовать свою мечту!",
];

function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

const forecastBtn = document.querySelector('.forecast-btn');
const currentForecastTitle = document.querySelector('.current-forecast h1');
const currentForecastParagraph = document.querySelector('.current-forecast p');
const forecastsContainer = document.querySelector('.forecasts');
const forecastTemplate = document.getElementById('forecast-item').content;

forecastBtn.addEventListener('click', () => {
const predictionIndex = getRandomNumber(0, predictions.length - 1);
const predictionText = predictions[predictionIndex];
const successProbability = getRandomNumber(0, 100);

currentForecastTitle.textContent = predictionText;
currentForecastParagraph.textContent = `Вероятность: ${successProbability}%`;

addForecastToList(predictionText, successProbability);
});

function addForecastToList(predictionText, successProbability) {
const forecastItem = document.importNode(forecastTemplate, true);
forecastItem.querySelector('h3').textContent = predictionText;
forecastItem.querySelector('p').textContent = `Вероятность: ${successProbability}%`;

forecastsContainer.prepend(forecastItem);
}