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

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


const forecastBtn = document.querySelector('.forecast-btn');
const currentForecast = document.querySelector('.current-forecast');
const forecastsContainer = document.querySelector('.forecasts');
const forecastTemplate = document.getElementById('forecast-item');


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


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);


forecastClone.querySelector('h3').textContent = prediction.text;


forecastsContainer.insertBefore(forecastClone, forecastsContainer.firstChild);
});