جواب «Welcome Steps» چالش 6 از جلسهی 14
سؤال
خیلی از اپها اول چند صفحهی خوشآمد دارند. آرایهی steps ترتیب صفحهها را دارد. تابع goNext() را بنویس: step را یکی زیاد کند و show(steps[step]) را صدا بزند. وقتی به "s3" رسیدی، متن دکمهی #next بشود Done. وقتی به "home" رسیدی، خود دکمهی #next پنهان شود.
راهنما
بعد از show(steps[step]) دو if بنویس: if (steps[step] === "s3") برای متن Done و if (steps[step] === "home") برای style.display = "none" روی دکمه.
یک جواب درست
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Water Counter</title>
<style>
body { font-family: sans-serif; margin: 0; }
.screen { max-width: 420px; margin: 0 auto; padding: 16px; display: none; }
#s1 { display: block; }
.screen-bar { max-width: 420px; margin: 0 auto; padding: 16px; }
button { min-height: 44px; font-size: 16px; width: 100%; }
</style>
</head>
<body>
<section class="screen" id="s1">
<h1>Welcome!</h1>
<p>This app helps you drink more water.</p>
</section>
<section class="screen" id="s2">
<h1>Tap + for every glass</h1>
<p>One tap, one glass.</p>
</section>
<section class="screen" id="s3">
<h1>Your numbers stay here</h1>
<p>Only you can see them.</p>
</section>
<section class="screen" id="home">
<h1>Today: 0 glasses</h1>
</section>
<div class="screen-bar">
<button id="next" onclick="goNext()">Next</button>
</div>
<script>
let steps = ["s1", "s2", "s3", "home"];
let step = 0;
function show(name) {
let screens = document.querySelectorAll(".screen");
for (let screen of screens) {
screen.style.display = "none";
}
document.getElementById(name).style.display = "block";
}
function goNext() {
step = step + 1;
show(steps[step]);
let button = document.getElementById("next");
if (steps[step] === "s3") {
button.textContent = "Done";
}
if (steps[step] === "home") {
button.style.display = "none";
}
}
</script>
</body>
</html>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن