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

Colour Themes چالش 8 از جلسه‌ی 15، سخت

دفترچه‌ی خاطرات سه رنگ دارد. CSS آماده است: کلاس‌های theme-blue، theme-green و theme-pink روی body متغیر --main را عوض می‌کنند. تابع setTheme(name) را بنویس: هر سه کلاس را از body بردارد، "theme-" + name را بگذارد و name را با salam.save("theme", name) ذخیره کند. آخر اسکریپت setTheme(salam.load("theme", "blue")) را صدا بزن.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Diary</title>
<style>
body { font-family: sans-serif; margin: 0; }
body.theme-blue { --main: #1e88e5; }
body.theme-green { --main: #2e7d32; }
body.theme-pink { --main: #d81b60; }
header { background-color: var(--main); color: white; padding: 12px 16px; }
.app { max-width: 420px; margin: 0 auto; padding: 16px; }
button { min-height: 44px; font-size: 16px; }
</style>
</head>
<body>
<header><h1>My Diary</h1></header>
<div class="app">
  <p>Pick a colour for your app:</p>
  <button id="blue" onclick="setTheme('blue')">Blue</button>
  <button id="green" onclick="setTheme('green')">Green</button>
  <button id="pink" onclick="setTheme('pink')">Pink</button>
</div>

<script>
function setTheme(name) {
  // remove the three theme classes, add the new one, save it
}
</script>
</body>
</html>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 15: تنظیمات

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