Kod
<!-- 4 sekcje w 3 losowych sekcjach pojawia się losowa liczba a w 4 mojawia się suma liczb -->
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
</head>
<body>
<section></section>
<section></section>
<section></section>
<section></section>
<script>
let sekcje = document.querySelectorAll("section")
let losowa = Math.round(Math.random() * sekcje.length)
if (losowa == sekcje.length) {
losowa = losowa - 1
}
let tabSumy = []
let suma = 0
console.log(losowa)
for (let i = 0; i <= sekcje.length; i++) {
if (i != sekcje.length) {
tabSumy[i] = Math.round(Math.random() * 1000)
sekcje[i].innerText = tabSumy[i]
suma += tabSumy[i]
}
}
sekcje[losowa].innerText = `Suma: ${suma}`
console.log(suma)
</script>
</body>
</html>