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

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

const btn = document.querySelector('.forecast-btn');
const currentForecast = document.querySelector('.current-forecast');
const currentForecastP = currentForecast.querySelector('p');
const currentForecastH1 = currentForecast.querySelector('h1');
const template = document.querySelector('#forecast-item');
const forecasts = document.querySelector('.forecasts');


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


btn.addEventListener('click', function() {

let predictionNumber = getRandom(1, 5);
let predictionText = "";

if (predictionNumber == 1) {
predictionText = "Ваша цель достижима.";
} else if (predictionNumber == 2) {
predictionText = "Ориентируйся на маленькие победы - они повлекут за собой большие!";
} else if (predictionNumber == 3) {
predictionText = "Осторожно, впереди волна впечатлений!";
} else if (predictionNumber == 4) {
predictionText = "Улыбайся! Кто-то может влюбиться в твою улыбку!";
} else {
predictionText = "Не оставляйте усилий и получите желаемое!";
}

currentForecastH1.textContent = predictionText;
currentForecastP.textContent = getRandom(1, 100);

const myTemplate = template.content.cloneNode(true);
myTemplate.querySelector('h3').textContent = predictionText;
myTemplate.querySelector('p').textContent = getRandom(1, 100);

forecasts.append(myTemplate);
});