جواب «The Counter Remembers» چالش 1 از جلسهی 39
سؤال
این شمارنده بعد از بسته شدن صفحه به صفر برمیگردد.
۱. count را با salam.load<number>("count", 0) بخوان.
۲. در press، بعد از زیاد کردن، با salam.save("count", count); نگهش دار.
اول برنامه باید Count: 0 باشد. بعد از دو کلیک و باز کردن دوبارهی صفحه: Count: 2.
راهنما
خط اول: let count = salam.load<number>("count", 0);. در press بعد از count = count + 1; بنویس salam.save("count", count);
یک جواب درست
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
#out { direction: ltr; text-align: left; font: 16px monospace; margin: 12px 0; padding: 12px; min-height: 28px; border-radius: 12px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out .line { min-height: 22px; }
</style>
<button id="go" onclick="press()">+1</button>
<pre id="out"></pre>
<script type="text/typescript">
let count = salam.load<number>("count", 0);
function press(): void {
count = count + 1;
salam.save("count", count);
show("Count: " + count);
}
show("Count: " + count);
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن