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

Three Screens, One Loop چالش 3 از جلسه‌ی 14، آسان

این اپ سه صفحه دارد که همه کلاس screen دارند: #home، #list و #settings. تابع show(name) را کامل کن: با یک حلقه‌ی for همه‌ی screens را پنهان کند و بعد صفحه‌ی name را نشان بدهد.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My App</title>
<style>
body { font-family: sans-serif; margin: 0; background-color: #f6f7fb; }
header { background-color: #3949ab; color: white; padding: 12px 16px; }
.screen { max-width: 420px; margin: 0 auto; padding: 16px 16px 90px; }
nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background-color: white; }
nav button { flex: 1; min-height: 56px; font-size: 16px; border: none; background-color: white; }
nav button.active { background-color: #ffd23f; font-weight: bold; }
#list, #settings { display: none; }
</style>
</head>
<body>
<header><h1 id="title">My App</h1></header>

<section class="screen" id="home">
  <h2>Home</h2>
  <p>Welcome! Pick a screen below.</p>
</section>

<section class="screen" id="list">
  <h2>My List</h2>
  <ul>
    <li>Read a book</li>
    <li>Drink water</li>
  </ul>
</section>

<section class="screen" id="settings">
  <h2>Settings</h2>
  <p>Nothing here yet.</p>
</section>

<nav>
  <button id="tab-home" onclick="show('home')">Home</button>
  <button id="tab-list" onclick="show('list')">List</button>
  <button id="tab-settings" onclick="show('settings')">Settings</button>
</nav>

<script>
function show(name) {
  let screens = document.querySelectorAll(".screen");
  // hide every screen in screens, then show the one called name
}
</script>
</body>
</html>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 14: چند صفحه · چالش بعدی: Mark the Active Tab

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