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

Portable Water Counter چالش 7 از جلسه‌ی 17، سخت

یک شمارنده‌ی آب آماده‌ی گوشی بساز. (۱) عنوان صفحه Water باشد و theme-color آن #0288d1. (۲) addGlass() تعداد لیوان‌ها را یکی زیاد کند، در #count بنویسد و با salam.save("water", count) ذخیره کند. (۳) هدف از اول 8 است و با salam.save("goal", goal) ذخیره می‌شود. changeGoal() عدد #goal را داخل try بخواند (اگر خالی یا غیرعدد بود خطای Please type a number. را در #msg نشان بدهد). (۴) #left همیشه بنویسد مثلاً 6 glasses left، و وقتی به هدف رسیدی Goal reached!. همه‌چیز موقع باز شدن اپ از salam.load خوانده شود.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<style>
body { font-family: sans-serif; margin: 0; }
header { background-color: #0288d1; color: white; padding: 12px 16px; }
.app { max-width: 420px; margin: 0 auto; padding: 16px; }
button, input, textarea { font-size: 16px; min-height: 44px; }
textarea { width: 100%; box-sizing: border-box; }
</style>
</head>
<body>
<header><h1>Water</h1></header>
<div class="app">
  <p>Glasses today:</p>
  <h2 id="count">0</h2>
  <button id="plus" onclick="addGlass()">+1 glass</button>
  <p id="left"></p>
  <p>
    <label for="goal">My goal (glasses)</label>
    <input id="goal" inputmode="numeric" placeholder="8">
    <button id="setGoal" onclick="changeGoal()">Set goal</button>
  </p>
  <p id="msg"></p>
</div>

<script>
let count = 0;
let goal = 8;

function addGlass() {
  // one more glass: show it, save it, update #left
}

function changeGoal() {
  // read #goal inside try; show a kind message in #msg if it is not a number
}
</script>
</body>
</html>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 17: خروجی و نصب · چالش بعدی: Import Words Safely

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