بتل کد Battle Codeدارد باز می‌شود…

Welcome Steps چالش 6 از جلسه‌ی 14، متوسط

خیلی از اپ‌ها اول چند صفحه‌ی خوش‌آمد دارند. آرایه‌ی steps ترتیب صفحه‌ها را دارد. تابع goNext() را بنویس: step را یکی زیاد کند و show(steps[step]) را صدا بزند. وقتی به "s3" رسیدی، متن دکمه‌ی #next بشود Done. وقتی به "home" رسیدی، خود دکمه‌ی #next پنهان شود.

<!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() {
  // next screen; Done on s3; hide the button on home
}
</script>
</body>
</html>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 14: چند صفحه · چالش بعدی: Add Here, See There

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js