Step 2: Red to Green چالش 2 از جلسهی 14، متوسط
حالا دکمهی Next را زنده کن. داخل جعبهی دکمه بنویس:
اگر color برابر red بود:
- color را green کن.
- چراغ قرمز را خاموش و چراغ سبز را روشن کن.
- در msg بنویس Go.
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.traffic { width: 70px; margin: 12px auto; padding: 10px; border-radius: 16px; background: #1e293b; }
.light { width: 50px; height: 50px; margin: 8px auto; border-radius: 50%; background: #64748b; }
#red.on { background: red; }
#yellow.on { background: gold; }
#green.on { background: limegreen; }
.board { font-size: 40px; width: 200px; margin: 12px auto; padding: 10px; border-radius: 12px; background: #e2e8f0; }
</style>
<div class="traffic">
<div id="red" class="light"></div>
<div id="yellow" class="light"></div>
<div id="green" class="light"></div>
</div>
<button id="next" onclick="press()">Next</button>
<p id="msg"></p>
<p id="walk">Walk</p>
<div id="board" class="board">0</div>
<script>
let red = document.getElementById("red");
let yellow = document.getElementById("yellow");
let green = document.getElementById("green");
let line = document.getElementById("msg");
let color = "red";
red.classList.add("on");
line.textContent = "Stop";
function press() {
}
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 14: پروژه: چراغ راهنما · چالش بعدی: Step 3: The Whole Cycle
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js