Bars from a List چالش 2 از جلسهی 12، آسان
تابع render() را کامل کن: #chart را خالی کن و برای هر عدد heights یک div با کلاس bar بساز که قدش همان عدد به پیکسل است، و آن را در #chart بگذار. دکمهی #add عدد 100 را اضافه میکند و دوباره میکشد.
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { font-family: Tahoma, sans-serif; margin: 0; background: #f4f6fb; color: #222; }
.screen { max-width: 420px; margin: 0 auto; padding: 16px; }
input, select { font-size: 16px; min-height: 44px; box-sizing: border-box; }
button { font-size: 16px; min-height: 44px; padding: 0 16px; }
</style>
<style>
#chart { display: flex; align-items: flex-end; gap: 8px; border-bottom: 2px solid #333; min-height: 20px; }
.bar { width: 36px; background: #4a90e2; border-radius: 6px 6px 0 0; }
</style>
<div class="screen" dir="rtl">
<h1>میلهها</h1>
<div id="chart"></div>
<button id="add" onclick="heights.push(100); render()">میلهی تازه</button>
</div>
<script>
let heights = [50, 120, 80];
function render() {
let chart = document.getElementById("chart");
chart.textContent = "";
// one bar for each number
}
render();
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 12: نمودار ساده · چالش بعدی: Biggest Is Full
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js