<!-- 4 sekcje 100 px wysokości, po każdym odświerzeniu ekranu losuje kolor tła -->
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<style>
section{
height: 100px;
}
</style>
</head>
<body>
<section></section>
<section></section>
<section></section>
<section></section>
<script>
const sekcje = document.querySelectorAll(`section`)
// Stare ↓
// for (let i = 0; i<=3; i++) {
// let liczba1 = Math.floor(Math.random()*255+1)
// let liczba2 = Math.floor(Math.random()*255+1)
// let liczba3 = Math.floor(Math.random()*255+1)
// sekcje[i].style.background = `rgb(${liczba1}, ${liczba2},${liczba3})`
// }
// Nowe ↓
sekcje.forEach(element => {
let liczba1 = Math.floor(Math.random()*255+1)
let liczba2 = Math.floor(Math.random()*255+1)
let liczba3 = Math.floor(Math.random()*255+1)
element.style.background = `rgb(${liczba1}, ${liczba2},${liczba3})`
});
</script>
</body>
</html>