There and Back چالش 2 از جلسهی 14، آسان
حالا یک تابع برای هر دو جهت! دکمهها show('about') و show('home') را صدا میزنند. تابع show(name) را بنویس: هر دو صفحهی "home" و "about" را پنهان کند و بعد صفحهای را که اسمش name است نشان بدهد.
<!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; }
button { min-height: 44px; font-size: 16px; }
#about { display: none; }
</style>
</head>
<body>
<section class="screen" id="home">
<h1>Water Counter</h1>
<p>Count the glasses of water you drink.</p>
<button id="toAbout" onclick="show('about')">About this app</button>
</section>
<section class="screen" id="about">
<h1>About</h1>
<p>Made by Sara in the app course.</p>
<button id="back" onclick="show('home')">Back</button>
</section>
<script>
function show(name) {
// 1. hide both screens: "home" and "about"
// 2. show the screen whose id is name
}
</script>
</body>
</html>
راهنما و جواب این چالش · برگشت به درس جلسهی 14: چند صفحه · چالش بعدی: Three Screens, One Loop
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js