Chapterبەش 7 · Lectureوانە 7.1

A First Look at JavaScript: Making Pages Interactiveسەرەتایەک بۆ JavaScript: لاپەڕەی کارلێککار

How JavaScript makes a page react: linking a script with defer (or type="module"), the console and its error messages, just enough values and variables, the DOM tree and querySelector, changing text, classes and visibility, events with addEventListener, three patterns — a dark-mode button, a phone menu button with aria-expanded and a live characters-left message — and progressive enhancement, so the page still works when a script fails.

چۆن لاپەڕەیەک کارلێککار دەکات: بەستنەوەی بە defer (یان type="module")، و ، ئەوەندەی پێویستە لە و ، داری و querySelector، گۆڕینی دەق، کلاس و دەرکەوتن، بە addEventListener، سێ نموونە — ، مێنیوی مۆبایل بە aria-expanded و پەیامێکی زیندووی «چەند ماوە» — هەروەها ، بۆ ئەوەی لاپەڕەکە کاتێک سەرنەکەوت هەر کار بکات.

20 min read20 خولەک خوێندنەوە · 16 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain what JavaScript adds to HTML and CSS, and where it runs.
  • Link a script with defer or type="module", and read messages and errors in the console.
  • Use const, let, strings, numbers and template literals in small scripts.
  • Find elements in the DOM with querySelector and change their text, classes and visibility.
  • React to clicks and typing with addEventListener, including an accessible menu button and a dark-mode button.
  • Build pages by progressive enhancement, so they work even when JavaScript does not.
  • ڕوون بکەیتەوە چی بۆ و زیاد دەکات و لە کوێ کار دەکات.
  • بە defer یان type="module" ببەستیتەوە و پەیام و لە بخوێنیتەوە.
  • const، let، ، ژمارە و template literal لە بچووکدا بەکار بهێنیت.
  • بە querySelector لە بدۆزیتەوە و دەق، کلاس و دەرکەوتنیان بگۆڕیت.
  • بە addEventListener وەڵامی کلیک و نووسین بدەیتەوە، لەوانە مێنیوی گونجاو بۆ هەمووان و .
  • لاپەڕە بە دروست بکەیت، بۆ ئەوەی تەنانەت کاتێک کار ناکات هەر کار بکەن.

What JavaScript adds to a pageJavaScript چی بۆ لاپەڕە زیاد دەکات؟

Every web page is built in three layers (What is web design?): HTML says what each part is, CSS decides how it looks, and JavaScript decides what it does. JavaScript is a whose code comes with the page and runs inside the visitor's browser, on their own phone or computer: it is code, while PHP runs on the server (Server-side and client-side languages).

هەموو لە سێ چین دروست دەبێت (دیزاینی وێب چییە؟): دەڵێت هەر بەشێک چییە، بڕیار دەدات چۆن دەردەکەوێت و بڕیار دەدات چی دەکات. کە کۆدەکەی لەگەڵ لاپەڕەکەدا دێت و لەناو سەردانیکەردا، لەسەر مۆبایل یان خۆی، کار دەکات: کۆدی ، لە کاتێکدا لەسەر کار دەکات (زمانەکانی لای ڕاژەکار و لای ڕاژەخواز).

  • React to clicks, taps and key presses.
  • Change its own text and look without loading a new page.
  • Check a form while people type, before it is sent.
  • Fetch new data in the background — that comes in the next lesson (Ajax and fetch()).
  • وەڵامی کلیک، دەستلێدان و داگرتنی بداتەوە.
  • دەق و ڕووخساری خۆی بگۆڕێت بێ ئەوەی لاپەڕەیەکی نوێ بار بکات.
  • لە کاتی نووسیندا، پێش ناردنی، بپشکنێت.
  • لە پشتەوە نوێ بهێنێت — ئەمە لە وانەی داهاتوودا دێت (Ajax و ⁦fetch()⁩).
A three-tier cake: HTML (structure) at the bottom, CSS (presentation) in the middle and JavaScript (behaviour) on top. Lines from the JavaScript tier lead to four cards: reacts to clicks, taps and keys; changes its text and look with no new page; checks a form while people type; fetches new data in the background.کێکێکی سێ نهۆمی: HTML (پێکهاتە) لە خوارەوە، CSS (ڕووخسار) لە ناوەڕاست و JavaScript (ڕەفتار) لە سەرەوە. هێڵەکان لە نهۆمی JavaScriptـەوە دەچن بۆ چوار کارت: وەڵامی کلیک، دەستلێدان و دوگمەکانی کیبۆرد دەداتەوە؛ دەق و ڕووخساری خۆی بێ لاپەڕەی نوێ دەگۆڕێت؛ فۆرمێک لە کاتی نووسیندا دەپشکنێت؛ لە پشتەوە دراوەی نوێ دەهێنێت.
MDN calls JavaScript the third layer of the cake: it builds on HTML and CSS.MDN بە دەڵێت چینی سێیەمی کێکەکە: لەسەر و بنیات دەنرێت.CêIT

Adding JavaScript to a pageزیادکردنی JavaScript بۆ لاپەڕە

Put your JavaScript in its own file, such as script.js, next to index.html (one site, one folder: A website is a folder). Link it in the <head> with <script src="script.js" defer></script>. defer means: download the file now, but run it only after the browser has read the whole page — so every element the script looks for already exists (Where does a script go?). It also works when you open the page by double-clicking it.

لە فایلێکی تایبەت بە خۆیدا دابنێ، وەک script.js، لە تەنیشت index.html (یەک ، یەک : تۆڕگە فۆڵدەرێکە). لە <head>ـدا بە <script src="script.js" defer></script> بیبەستەرەوە. defer واتە: فایلەکە ئێستا دابار بکە، بەڵام تەنیا دوای ئەوەی هەموو لاپەڕەکەی خوێندەوە جێبەجێی بکە — بۆیە هەموو ئەو بەدوایاندا دەگەڕێت پێشتر هەن (دەسنووس لە کوێ دادەنرێت؟). کاتێک لاپەڕەکە بە دەکەیتەوەش کار دەکات.

A page that links its script in the headلاپەڕەیەک کە دەسنووسەکەی لە <head>ـدا دەبەستێتەوەindex.htmlHTMLRuns in the browserلە ناو تۆڕگەڕ کار دەکات
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Shilan's Bakery</title>
  <link rel="stylesheet" href="style.css">
  <script src="script.js" defer></script>
</head>
<body>
  <h1>Shilan's Bakery</h1>
  <p id="cakes-left">7 cakes left today</p>
  <button type="button" id="order">Order a cake</button>
</body>
</html>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 7

style.css: the look (CSS).

style.css: ڕووخسار ().

Lineدێڕی 8

script.js: the behaviour. defer = run after the page has been read.

script.js: ڕەفتار. defer = دوای خوێندنەوەی لاپەڕەکە جێبەجێ بکە.

Adding JavaScript to a pageزیادکردنی JavaScript بۆ لاپەڕە

Why defer? And what about modules?بۆچی defer؟ ئەی type="module"؟

Without defer, a script in the <head> stops the browser: it must download and run the file before it reads the rest of the HTML. The page appears later, and the script cannot find the elements below it — querySelector() gives back null, and the console shows an error (next screen).

بێ defer، لە <head>ـدا ڕادەگرێت: دەبێت فایلەکە دابار بکات و جێبەجێی بکات پێش ئەوەی باقیی بخوێنێتەوە. لاپەڕەکە دواتر دەردەکەوێت و ناتوانێت ئەو بدۆزێتەوە کە لە خوارییەوەن — querySelector() null دەگەڕێنێتەوە و پیشان دەدات (شاشەی داهاتوو).

Three timelines. A script without defer: reading the HTML stops while the script downloads and runs, so the script runs before the rest of the page exists. A script with defer: the HTML is read without a stop while the file downloads at the same time, and the script runs after the whole page is ready. A module script: the same as defer, but only from a web server, never from file://.سێ هێڵی کات. دەسنووسێک بێ defer: خوێندنەوەی HTML ڕادەوەستێت تا دەسنووسەکە دابار دەکرێت و جێبەجێ دەبێت، بۆیە دەسنووسەکە پێش باقیی لاپەڕەکە کار دەکات. دەسنووسێک بە defer: HTML بێ وەستان دەخوێنرێتەوە و هاوکات فایلەکە دابار دەکرێت، دەسنووسەکە دوای ئامادەبوونی هەموو لاپەڕەکە جێبەجێ دەبێت. دەسنووسێک بە type="module": وەک defer، بەڵام تەنیا لە ڕاژەکاری وێبەوە، هەرگیز لە file://ـەوە نا.
defer and module scripts wait for the page; a plain script in the head blocks it.defer و type="module" چاوەڕێی لاپەڕەکە دەکەن؛ ئاسایی لە <head>ـدا ڕێگری لێ دەکات.CêIT

A modern alternative is <script type="module" src="script.js"></script>. Modules wait for the page by themselves (they are deferred by default), but browsers load them only from a web server: opened as file://, the console reports a CORS policy error. Use a local server such as Live Preview, python3 -m http.server or XAMPP (file:// or http://localhost?). This lesson uses defer, so every example also works by double-clicking.

ڕێگەیەکی نوێتر <script type="module" src="script.js"></script>ـە. ئەم جۆرە خۆیان چاوەڕێی لاپەڕەکە دەکەن (بە شێوەی بنەڕەتی دوادەخرێن)، بەڵام تەنیا لە باریان دەکەن: ئەگەر بە file:// بکرێتەوە، CORS policy ڕادەگەیەنێت. ناوخۆیی وەک Live Preview، python3 -m http.server یان XAMPP بەکاربهێنە (file:// یان http://localhost؟). ئەم وانەیە defer بەکار دەهێنێت، بۆیە هەموو نموونەکان بە کار دەکەن.

The console: where JavaScript talks to youکۆنسۆڵ: شوێنی قسەکردنی JavaScript لەگەڵت

Open the (F12, or right-click → Inspect) and choose Console (Browsers and developer tools). console.log() writes a message there — your best friend while you learn. When something goes wrong, the error appears in red with its type, a message and the file and line (script.js:5): click it to jump to that line. You can also type JavaScript in the console and press Enter to try it at once.

بکەرەوە (⁦F12⁩، یان کلیکی ڕاست ← Inspect) و Console هەڵبژێرە (تۆڕگەڕ و ئامرازەکانی گەشەپێدەر). console.log() پەیامێک لەوێ دەنووسێت — باشترین هاوڕێتە لە کاتی فێربووندا. کاتێک شتێک تێکدەچێت، بە سوور دەردەکەوێت لەگەڵ جۆرەکەی، پەیامێک و ناوی فایل و ژمارەی دێڕ (script.js:5): کلیکی لێ بکە بۆ ئەوەی بچیتە سەر ئەو دێڕە. هەروەها دەتوانیت لە بنووسیت و Enter دابگریت بۆ ئەوەی یەکسەر تاقی بکەیتەوە.

The Console panel of the developer tools. Two normal lines: Hello from script.js! and Cakes left: 7, each with its file and line on the right. Under them a red line: Uncaught TypeError: Cannot read properties of null (reading 'addEventListener'), at script.js:5:8, with the link script.js:5. At the bottom a prompt where you can type JavaScript. Four labels explain the messages, the red error, the file-and-line link and the prompt.پانێڵی Console لە ئامرازەکانی گەشەپێدەر. دوو دێڕی ئاسایی: Hello from script.js! و Cakes left: 7، هەریەکە لەگەڵ فایل و دێڕەکەی لە لای ڕاست. لە ژێریاندا دێڕێکی سوور: Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')، at script.js:5:8، لەگەڵ بەستەری script.js:5. لە خوارەوە شوێنێک بۆ نووسینی JavaScript. چوار نیشانە پەیامەکان، هەڵە سوورەکە، بەستەری فایل و دێڕ و شوێنی نووسین ڕوون دەکەنەوە.
Read the red line from left to right: what went wrong, then where.دێڕە سوورەکە لە چەپەوە بۆ ڕاست بخوێنەوە: چی هەڵە بوو، پاشان لە کوێ.CêIT
A first script with a bug in itیەکەم دەسنووس کە باگێکی تێدایەscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
console.log("Hello from script.js!");
console.log("Cakes left:", 7);

const button = document.querySelector("#order-button");
button.addEventListener("click", () => {
  console.log("Clicked!");
});
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 1-2

console.log() writes a message, and also numbers or several values.

console.log() پەیامێک دەنووسێت، هەروەها ژمارە یان چەند .

Lineدێڕی 4

The selector has a typo: the HTML says id="order".

هەڵەی نووسینی تێدایە: دەڵێت id="order".

Just enough JavaScript: values and variablesئەوەندەی پێویستە لە JavaScript: نرخەکان و گۆڕاوەکان

A variable is a named box for a value (What is a variable?). In JavaScript you make one with const when the value will not change and with let when it will — MDN's rule: "const when you can, let when you have to". The old var is not needed any more. Text goes in quotes (a ); numbers do not. A template literal is text in backticks that puts values inside with ${…}, like Python's f-strings (f-strings). Names are : cakesLeft is not cakesleft.

سندووقێکی ناونراوە بۆ (گۆڕاو چییە؟). لە بە const دروستی دەکەیت کاتێک ناگۆڕێت و بە let کاتێک دەگۆڕێت — یاسای MDN: «const هەر کاتێک دەتوانیت، let کاتێک ناچاریت». varـی کۆن چیتر پێویست نییە. دەق لەناو دەنووسرێت ()؛ ژمارە نا. نێو `…` ⁦(template literal)⁩ بە ${…} دەخاتە ناو دەقەوە ()، وەک ⁦f-string⁩ـی Python (⁦f-string⁩). ناوەکان : cakesLeft هەمان cakesleft نییە.

Three labelled boxes: const shop holds "Shilan's Bakery" (a string, text in quotes, with a lock), const price holds 1500 (a number, no quotes, with a lock) and let cakesLeft holds 7, crossed out and changed to 6 (let: the value can change). Below, the template literal ${cakesLeft} cakes left at ${price} dinars each becomes "6 cakes left at 1500 dinars each".سێ سندووقی ناونراو: const shop نرخی "Shilan's Bakery" هەڵدەگرێت (زنجیرەنووسە، دەق لەناو نیشانەی گوتەدا، بە قوفڵێکەوە)، const price نرخی 1500 (نرخێکی ژمارەیی بێ نیشانەی گوتە، بە قوفڵێکەوە) و let cakesLeft نرخی 7 کە هێڵی بەسەردا هاتووە و بووە بە 6 (let: نرخەکە دەتوانێت بگۆڕێت). لە خوارەوە زنجیرەنووسەی `${cakesLeft} cakes left at ${price} dinars each` دەبێت بە "6 cakes left at 1500 dinars each".
const for values that stay, let for values that change.const بۆ ئەو دەمێننەوە، let بۆ ئەوانەی دەگۆڕێن.CêIT
Values, variables and a template literalنرخەکان، گۆڕاوەکان و template literalvalues.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const shop = "Shilan's Bakery";   // a string: text in quotes
const price = 1500;               // a number (dinars)
let cakesLeft = 7;                // let: this value will change

cakesLeft = cakesLeft - 1;        // one cake sold

console.log(shop);
console.log(`${cakesLeft} cakes left at ${price} dinars each`);
console.log("Two cakes cost", 2 * price, "dinars");
console.log("5" + 5, 5 + 5);
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

let: cakesLeft will change on line 5.

let: cakesLeft لە دێڕی 5ـدا دەگۆڕێت.

Lineدێڕی 8

A template literal: backticks, and values inside ${ }.

template literal: دەق لەناو `…`ـدا و لەناو ${ }.

The DOM: your page as a treeDOM: لاپەڕەکەت وەک دارێک

Definitionپێناسە

The Document Object Model: the 's tree of objects that stands for the loaded page. reads and changes this tree, and the browser redraws the page at once.

Document Object Model: داری ئۆبجێکتەکانی کە نوێنەرایەتیی ئەو لاپەڕەیە دەکات کە بارکراوە. ئەم دارە دەخوێنێتەوە و دەیگۆڕێت و یەکسەر لاپەڕەکە دووپاتە دەکێشێتەوە.

When the browser reads your HTML, it builds the DOM (Document Object Model): a tree with one for every element and every piece of text. <html> is the ; <head> and <body> are its children, and each element inside an element is a child of it. JavaScript never edits your HTML file: it reads and changes this tree, and the browser redraws the screen at once.

کاتێک دەخوێنێتەوە، DOM ⁦(Document Object Model)⁩ دروست دەکات: کە بۆ هەموو و هەموو پارچە دەقێک تێدایە. <html> ؛ <head> و <body> منداڵەکانی ئەون و هەر کە لەناو تردایە منداڵی ئەوە. هەرگیز فایلی دەستکاری ناکات: ئەم دەخوێنێتەوە و دەیگۆڕێت و یەکسەر شاشەکە دووپاتە دەکێشێتەوە.

To change an element, first find it with document.querySelector(). It takes a CSS selector — the same #id, .class and tag selectors you use in CSS (Class selectors) — and gives back the first element that matches, or null when nothing matches. document.querySelectorAll() gives back all the matches.

بۆ گۆڕینی ، سەرەتا بە document.querySelector() بیدۆزەرەوە. وەردەگرێت — هەمان #id، .class و ناوی تاگ کە لە بەکاری دەهێنیت (هەڵبژێری کلاس) — و یەکەم کە دەگونجێت دەگەڕێنێتەوە، یان null ئەگەر هیچ نەگونجێت. document.querySelectorAll() هەموو ئەوانەی دەگونجێن دەگەڕێنێتەوە.

On one side the HTML of a small page; on the other the same page as a tree: document, then html (the root), then head and body. head holds title with the text node "Shilan's Bakery"; body holds h1, p#cakes-left with the text node "7 cakes left today", and button#order. A box with document.querySelector("#cakes-left") points to the p#cakes-left node, which is highlighted, as is its line in the HTML.لە لایەکەوە HTMLـی لاپەڕەیەکی بچووک؛ لە لاکەی ترەوە هەمان لاپەڕە وەک دارێک: document، پاشان html (نۆدی ڕەگ)، پاشان head و body. head titleـی تێدایە لەگەڵ نۆدی دەقی "Shilan's Bakery"؛ body h1، p#cakes-left لەگەڵ نۆدی دەقی "7 cakes left today" و button#orderـی تێدایە. سندووقێک بە document.querySelector("#cakes-left") ئاماژە بۆ نۆدی p#cakes-left دەکات کە ڕەنگی جیاوازە، هەروەها دێڕەکەی لە HTMLـدا.
One HTML element, one node in the tree; querySelector() finds it with a CSS selector.یەک ، یەک لە ؛ querySelector() بە دەیدۆزێتەوە.CêIT

The DOM: your page as a treeDOM: لاپەڕەکەت وەک دارێک

Changing text, classes and visibilityگۆڕینی دەق، کلاس و دەرکەوتن

Once you have an element, change it. textContent reads or replaces its text, always as plain text. classList.add(), .remove() and .toggle() add or remove a class, and your CSS decides what that class looks like. Prefer classes to the style property: the look stays in the CSS file, one class can change many properties, and themes and media queries keep working (MDN). hidden = true hides an element; hidden = false shows it again.

کاتێک دۆزییەوە، بیگۆڕە. textContent دەقەکەی دەخوێنێتەوە یان دەیگۆڕێت، هەمیشە وەک دەقی ئاسایی. classList.add()، .remove() و .toggle() کلاسێک زیاد یان لادەبەن و بڕیار دەدات ئەو کلاسە چۆن دەردەکەوێت. کلاس لە تایبەتمەندیی style باشترە: ڕووخسار لە فایلی دەمێنێتەوە، یەک کلاس دەتوانێت چەندین بگۆڕێت و و بەردەوام کار دەکەن ⁦(MDN)⁩. hidden = true دەشارێتەوە؛ hidden = false دووپاتە پیشانی دەداتەوە.

Three rows, each with a line of code and a before-and-after picture. textContent: "7 cakes left today" becomes "Only 2 cakes left today!". classList: note.classList.add("highlight") turns a plain line into a highlighted box. hidden: menu.hidden = true makes a list disappear.سێ ڕیز، هەریەکە بە دێڕێکی کۆد و وێنەیەکی پێش و دوا. textContent: "7 cakes left today" دەبێت بە "Only 2 cakes left today!". classList: note.classList.add("highlight") دێڕێکی ئاسایی دەکات بە سندووقێکی ڕەنگکراو. hidden: menu.hidden = true لیستێک ون دەکات.
Words with textContent, looks with classList, show and hide with hidden.وشە بە textContent، ڕووخسار بە classList، پیشاندان و شاردنەوە بە hidden.CêIT
Find two elements and change themدوو توخم بدۆزەرەوە و بیانگۆڕەscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const cakesText = document.querySelector("#cakes-left");
const note = document.querySelector(".note");

console.log(cakesText.textContent);      // read the text

cakesText.textContent = "Only 2 cakes left today!";   // change the words
note.classList.add("highlight");                      // change the look (CSS)
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

Reading: console.log shows the old text.

خوێندنەوە: console.log دەقە کۆنەکە پیشان دەدات.

Lineدێڕی 6-7

Writing: new words, and a class that CSS styles.

نووسین: وشەی نوێ و کلاسێک کە شێوەی دەدات.

Events: reacting to a clickڕووداوەکان: وەڵامدانەوەی کلیکێک

Definitionپێناسە

Something that happens while a program runs and that code can react to: a tap, a key press, a timer firing, data arriving or a value changing.

شتێکە کە لە کاتی کارکردنی ڕوو دەدات و کۆد دەتوانێت وەڵامی بداتەوە: دەستلێدانێک، داگرتنی دوگمەیەکی کیبۆرد، تەواوبوونی کاتژمێرێک، گەیشتنی دراوە یان گۆڕانی نرخێک.

On a web page an event is a click, a key press, typing in a field or the page finishing loading. addEventListener("click", function) asks the browser to run your function every time that event happens on that element; the function is called a (or handler). The order is always the same: click → event → your function → a change in the DOM → the browser redraws the page — with no new page from the server.

لە واتە کلیکێک، داگرتنی ، نووسین لە خانەیەکدا یان تەواوبوونی بارکردنی لاپەڕەکە. addEventListener("click", function) داوا لە دەکات هەر جارێک ئەو لەسەر ئەو ڕوو بدات جێبەجێ بکات؛ ئەم پێی دەگوترێت (یان handler). ڕیزبەندییەکە هەمیشە وەک یەکە: کلیک ← ← ← گۆڕانێک لە ← لاپەڕەکە دووپاتە دەکێشێتەوە — بێ لاپەڕەیەکی نوێ لە .

Five steps, side by side with the code. 1: the page shows 7 cakes left today and an Order a cake button; the addEventListener line is marked. 2: the mouse clicks the button and a click event appears. 3: the listener function runs and cakesLeft goes from 7 to 6. 4: textContent changes the text node of p#cakes-left in the DOM. 5: the page shows 6 cakes left today; only that line changed and nothing was loaded again.
Five steps, side by side with the code. 1: the page shows 7 cakes left today and an Order a cake button; the addEventListener line is marked. 2: the mouse clicks the button and a click event appears. 3: the listener function runs and cakesLeft goes from 7 to 6. 4: textContent changes the text node of p#cakes-left in the DOM. 5: the page shows 6 cakes left today; only that line changed and nothing was loaded again.
Click → event → function → DOM → screen.کلیک ← ← ← DOM ← شاشە.CêIT
Each click sells one cakeهەر کلیکێک کێکێک دەفرۆشێتscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const button = document.querySelector("#order");
const cakesText = document.querySelector("#cakes-left");
let cakesLeft = 7;

button.addEventListener("click", () => {
  cakesLeft = cakesLeft - 1;
  cakesText.textContent = `${cakesLeft} cakes left today`;
});
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 3

let: the number of cakes changes.

let: ژمارەی کێکەکان دەگۆڕێت.

Lineدێڕی 5

() => { … } is a short function with no name; the browser calls it on every click.

() => { … } کورتە؛ لە هەموو کلیکێکدا بانگی دەکات.

Lineدێڕی 6-7

Change the value, then the text in the DOM.

بگۆڕە، پاشان دەقەکە لە .

Events: reacting to a clickڕووداوەکان: وەڵامدانەوەی کلیکێک

Example: a dark-mode buttonنموونە: دوگمەیەکی دۆخی تاریک

In A dark theme the colours switch when the system setting changes. A button lets visitors choose for themselves: JavaScript only adds or removes one class, dark, on the <html> element (document.documentElement), and the custom properties do the rest. classList.toggle() adds the class when it is missing, removes it when it is there and gives back true when the class is now on. aria-pressed tells screen-reader users whether the toggle is on; the button's text stays “Dark mode” (WAI-ARIA).

لە دۆخی تاریکـدا ڕەنگەکان کاتێک ڕێکخستنی سیستەم دەگۆڕێت دەگۆڕێن. ڕێگە بە سەردانیکەران دەدات خۆیان هەڵبژێرن: تەنیا یەک کلاس، dark، بۆ <html> (document.documentElement) زیاد یان لادەبات و تایبەتمەندییە دڵخوازەکان باقیی کارەکە دەکەن. classList.toggle() کلاسەکە زیاد دەکات ئەگەر نەبێت، لای دەبات ئەگەر هەبێت و true دەگەڕێنێتەوە ئەگەر کلاسەکە ئێستا هەبێت. aria-pressed بە بەکارهێنەرانی دەڵێت سویچەکە هەڵکراوە یان نا؛ دەقی هەر «Dark mode» دەمێنێتەوە ⁦(WAI-ARIA)⁩.

Four steps with the page, the html tag, the code and the custom properties. 1: a light page; the Dark mode button has aria-pressed="false". 2: a click; classList.toggle adds class="dark" to the html tag. 3: :root.dark gives --color-bg, --color-text and --color-primary dark values and the page turns dark; aria-pressed is true. 4: a second click removes the class; the light colours return and aria-pressed is false.
Four steps with the page, the html tag, the code and the custom properties. 1: a light page; the Dark mode button has aria-pressed="false". 2: a click; classList.toggle adds class="dark" to the html tag. 3: :root.dark gives --color-bg, --color-text and --color-primary dark values and the page turns dark; aria-pressed is true. 4: a second click removes the class; the light colours return and aria-pressed is false.
JavaScript switches one class; the custom properties change every colour. یەک کلاس دەگۆڕێت؛ هەموو ڕەنگەکان دەگۆڕن.CêIT
style.css: the dark values for the classstyle.css: نرخەکانی تاریک بۆ کلاسەکەstyle.cssCSSRuns in the browserلە ناو تۆڕگەڕ کار دەکات
:root.dark {
  color-scheme: dark;              /* form controls and scrollbars follow */
  --color-bg: #121417;
  --color-text: #e8e6e3;
  --color-primary: #7fb2e5;
  --color-on-primary: #121417;
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 2

color-scheme: dark — form controls and scrollbars turn dark too.

color-scheme: dark — کۆنترۆڵەکانی و بەشەکانی تری تاریک دەبن.

Lineدێڕی 3-6

The light values stay in :root, as in the colour lesson.

ڕووناکەکان وەک وانەی ڕەنگ لە :rootـدا دەمێننەوە.

script.js: the button switches the classscript.js: دوگمەکە کلاسەکە دەگۆڕێتscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const themeButton = document.querySelector("#theme-button");

themeButton.addEventListener("click", () => {
  const isDark = document.documentElement.classList.toggle("dark");
  themeButton.setAttribute("aria-pressed", isDark);
});
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

toggle() gives back true when the class is now on.

toggle() true دەگەڕێنێتەوە کاتێک کلاسەکە ئێستا هەیە.

Lineدێڕی 5

Keep aria-pressed in step with the class.

aria-pressed لەگەڵ کلاسەکەدا یەکسان بهێڵەرەوە.

Example: a live “characters left” messageنموونە: پەیامێکی زیندووی «چەند نووسە ماوە»

Let HTML check what it can first: here maxlength="120" stops typing after 120 characters, and required, type="email" or pattern can do more (Checking answers: when and how). JavaScript then helps: the input event fires on every change, so the page can say how many characters are left while people type. The aria-live="polite" paragraph is read out when the typing pauses. Browser checks never replace the server: anyone can switch them off, so PHP must check again (Client-side checks are not security).

سەرەتا با ئەوە بپشکنێت کە دەتوانێت: لێرەدا maxlength="120" دوای ⁦120⁩ ڕێگە لە نووسین دەگرێت و required، type="email" یان pattern دەتوانن زیاتر بکەن (پشکنینی وەڵامەکان: کەی و چۆن). پاشان یارمەتی دەدات: input لە هەموو گۆڕانێکدا ڕوو دەدات، بۆیە لاپەڕەکە دەتوانێت لە کاتی نووسیندا بڵێت چەند ماوە. بڕگەی aria-live="polite" کاتێک نووسین دەوەستێت دەخوێنرێتەوە. پشکنینەکانی هەرگیز جێی ناگرنەوە: هەر کەسێک دەتوانێت بیانکوژێنێتەوە، بۆیە دەبێت دووپاتە بپشکنێتەوە (پشتڕاستکردنەوەی لای ڕاژەخواز ئاسایش نییە).

Three moments of the same form field, Message for the baker, with the hint Up to 120 characters. Start: the box is empty and the line under it says 120 characters left. Typing: Please write Shilan on the cake, and 89 characters left. At the limit: the box is full, 0 characters left, and maxlength stops more typing. Below: aria-live="polite" lets a screen reader read the count when typing pauses, and the server still checks the length again.سێ ساتی هەمان خانەی فۆرم، Message for the baker، لەگەڵ ڕێنمایی Up to 120 characters. سەرەتا: خانەکە بەتاڵە و دێڕی ژێری دەڵێت 120 characters left. نووسین: Please write Shilan on the cake و 89 characters left. گەیشتن بە سنوور: خانەکە پڕە، 0 characters left و maxlength ڕێگە لە نووسینی زیاتر دەگرێت. لە خوارەوە: aria-live="polite" ڕێگە بە خوێنەرەوەی شاشە دەدات کاتێک نووسین دەوەستێت ژمارەکە بخوێنێتەوە و ڕاژەکار هێشتا درێژییەکە دووپاتە دەپشکنێتەوە.
HTML sets the limit; JavaScript shows how much is left. سنوورەکە دادەنێت؛ پیشان دەدات چەندی ماوە.CêIT
script.js: count while people typescript.js: لە کاتی نووسیندا بژمێرەscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const message = document.querySelector("#message");
const counter = document.querySelector("#counter");

function updateCounter() {
  const left = message.maxLength - message.value.length;
  counter.textContent = `${left} characters left`;
}

message.addEventListener("input", updateCounter);
updateCounter();   // show "120 characters left" at the start
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4-7

A named function: it works out what is left and writes it in the page.

ناودار: حیسابی ئەوە دەکات کە ماوە و لە لاپەڕەکەدا دەینووسێت.

Lineدێڕی 9-10

Run it on every input event, and once at the start.

لە هەموو inputـدا جێبەجێی بکە و یەک جاریش لە سەرەتادا.

Progressive enhancement: HTML first, JavaScript lastباشترکردنی پلەبەپلە: سەرەتا HTML، JavaScript لە کۆتاییدا

Definitionپێناسە

Building a page in layers: first plain HTML that works for everyone, then CSS for the look, then JavaScript that improves it where it is available. If a script fails, the page still works.

دروستکردنی لاپەڕەیە بە چین چین: سەرەتا سادە کە بۆ هەمووان کار دەکات، پاشان بۆ شێوەکەی، پاشان کە لە هەر شوێنێک هەبێت باشتری دەکات. ئەگەر سەرنەکەوێت، لاپەڕەکە هەر کار دەکات.

Scripts fail more often than you think: a slow phone network, an old browser, a blocked file, one typing mistake that stops the whole script. So build in layers: first HTML that works for everyone — real links, real buttons, forms that send — then CSS for the look, then JavaScript that makes it nicer where it runs. The menu above follows this: without JavaScript every link is still on the page.

زیاتر لەوەی بیری لێ دەکەیتەوە سەرناکەون: هێواشی مۆبایل، کۆن، فایلێکی ڕێگەپێنەدراو، یەک هەڵەی نووسین کە هەموو ڕادەگرێت. بۆیە بە چین دروستی بکە: سەرەتا کە بۆ هەمووان کار دەکات — ڕاستەقینە، ڕاستەقینە و ڕاستەقینە کە دەنێردرێن — پاشان بۆ ڕووخسار، پاشان کە لەو شوێنانەی کار دەکات باشتری دەکات. مێنیوەکەی سەرەوە ئەمە پەیڕەو دەکات: بێ هەموو هەر لەسەر لاپەڕەکەن.

Three floors of a building with a small picture of the same menu on each. Floor 1, HTML: works for everyone with real links, buttons and forms — a plain list of four links. Floor 2, plus CSS: looks good — a coloured header with the links in a row. Floor 3, plus JavaScript: even better where scripts run — the header with a Menu button. Under them: if a layer fails, the floor below still works.سێ نهۆمی باڵەخانەیەک، لەسەر هەر نهۆمێک وێنەیەکی بچووکی هەمان مێنیو. نهۆمی 1، HTML: بۆ هەمووان کار دەکات بە بەستەر، دوگمە و فۆرمی ڕاستەقینە — لیستێکی سادەی چوار بەستەر. نهۆمی 2، + CSS: جوان دەردەکەوێت — سەرپەڕەیەکی ڕەنگکراو و بەستەرەکان لە یەک ڕیزدا. نهۆمی 3، + JavaScript: لەو شوێنانەی دەسنووس کار دەکات باشترە — سەرپەڕەکە بە دوگمەی Menu. لە ژێریاندا: ئەگەر چینێک سەرنەکەوت، نهۆمی خوارەوە هەر کار دەکات.
Each layer adds; none of them is required for the page to work.هەر چینێک شتێک زیاد دەکات؛ هیچیان بۆ کارکردنی لاپەڕەکە پێویست نییە.CêIT

Two habits help most: use real <a> and <button> elements, never clickable <div>s, so the keyboard and screen readers work (Everything with the keyboard); and keep the focus outline visible on everything your script makes clickable.

دوو خوو زۆرترین یارمەتی دەدەن: <a> و <button> بەکاربهێنە، هەرگیز <div>ـی کلیکپێکراو، بۆ ئەوەی و کار بکەن (هەموو شتێک بە کیبۆرد)؛ هەروەها لەسەر هەموو ئەو شتانەی کلیکپێکراویان دەکات دیار بهێڵەرەوە.

Where to go nextدواتر بۆ کوێ بچیت

This lesson showed the most useful part: scripts, the console, a few values, the DOM, events and three patterns. To go further:

ئەم وانەیە بەسوودترین بەشی پیشان دا: ، ، چەند ، ، و سێ نموونە. بۆ ئەوەی زیاتر بڕۆیت:

  • Next lesson: fetching data from the server without a new page (Ajax and fetch()).
  • MDN's free module *Dynamic scripting with JavaScript*: 23 lessons and challenges (November 2026) — conditions, loops, functions, arrays, objects, events, network requests and JSON.
  • Programming ideas in any language: CêIT's Programming course with Python or Java (Many languages for many jobs).
  • Your final project adds one small touch from this lesson — the menu button or the theme switch (Final Project: Your Portfolio Website).
  • Frameworks such as React, Vue or Svelte only after the basics: they are JavaScript too, and they still need good HTML, CSS and accessibility.
  • وانەی داهاتوو: هێنانی لە بێ لاپەڕەی نوێ (Ajax و ⁦fetch()⁩).
  • مۆدیولی بێبەرانبەری MDN، *Dynamic scripting with JavaScript*: ⁦23⁩ وانە و ڕاهێنان (تشرینی دووەمی ⁦2026⁩) — ، ، ، ، ، ، داواکاریی تۆڕ و .
  • بیرۆکەکانی لە هەر زمانێکدا: خولی CêIT بە Python یان Java (زۆر زمان بۆ زۆر کار).
  • پڕۆژەی کۆتایی یەک دەستکاریی بچووک لەم وانەیە زیاد دەکات — مێنیو یان سویچی (پڕۆژەی کۆتایی: پۆرتفۆلیۆی ئۆنلاینەکەت).
  • وەک React، Vue یان Svelte تەنیا دوای بنەڕەتەکان: ئەوانیش و هێشتا پێویستیان بە ، و باش هەیە.
A winding path with five numbered stones: 1 you are here, a first look; 2 the next lesson, fetch() and Ajax; 3 MDN's Dynamic scripting with JavaScript; 4 the Programming course with Python or Java; 5 later, frameworks such as React or Vue.ڕێگایەکی پێچاوپێچ بە پێنج بەردی ژمارەدار: 1 تۆ لێرەیت، سەرەتایەک؛ 2 وانەی داهاتوو، fetch() و Ajax؛ 3 Dynamic scripting with JavaScriptـی MDN؛ 4 خولی بەرنامەسازیی بە Python یان Java؛ 5 دواتر، فرەیموۆرکەکانی وەک React یان Vue.
Plain JavaScript first; frameworks build on it.سەرەتا سادە؛ لەسەری بنیات دەنرێن.CêIT

Common mistakesهەڵە باوەکان

MistakeهەڵەBetterباشتر
A script in the <head> without defer: it runs before the elements exist and finds null لە <head>ـدا بێ defer: پێش دروستبوونی کار دەکات و null دەدۆزێتەوەAdd defer, or use type="module" through a local serverdefer زیاد بکە، یان type="module" لە ڕێگەی ناوخۆییەوە بەکاربهێنە
A selector typo: querySelector("order") for id="order"هەڵەی نووسینی : querySelector("order") بۆ id="order"querySelector("#order"): copy the exact id with its # (or . for a class)querySelector("#order"): هەمان idـەکە لەگەڵ # (یان . بۆ کلاس) بنووسە
Wrong capitals: addeventListener, textcontentپیتی گەورەی هەڵە: addeventListener، textcontentJavaScript is case-sensitive: addEventListener, textContent : addEventListener، textContent
Setting style again and again from JavaScriptدانانی style جار لە دوای جار لە Add or remove a class; keep the look in the CSSکلاسێک زیاد یان لاببە؛ ڕووخسار لە بهێڵەرەوە
A clickable <div> or <span><div> یان <span>ـی کلیکپێکراوA real <button type="button">: Tab, Enter, Space and screen readers work<button type="button">ـی ڕاستەقینە: Tab، Enter، Space و کار دەکەن
Content that only a script can show (hidden in the HTML)ناوەڕۆکێک کە تەنیا دەتوانێت پیشانی بدات (لە شاراوە)Show it in the HTML; let the script hide it when it startsلە پیشانی بدە؛ با کاتێک دەست پێدەکات بیشارێتەوە
onclick="…" attributes in the HTML onclick="…" لە addEventListener() in script.jsaddEventListener() لە script.jsـدا
Putting typed text into innerHTMLخستنە ناوەوەی دەقی نووسراو بۆ innerHTMLtextContent: plain text, no hidden codetextContent: دەقی ئاسایی، بێ کۆدی شاراوە
Trusting the browser's checksمتمانەکردن بە پشکنینەکانی The server checks every value again هەموو دووپاتە دەپشکنێتەوە
Ignoring the consoleپشتگوێخستنی Keep it open: the red line names the error, the file and the lineکراوەی بهێڵەرەوە: دێڕە سوورەکە ناوی ، فایلەکە و دێڕەکە دەڵێت

Exercisesڕاهێنانەکان

ExerciseڕاهێنانA “more about our bread” buttonدوگمەیەکی «زیاتر لەبارەی نانەکەمان»

Make the button show and hide the second paragraph. Without JavaScript the text must stay visible; with JavaScript the button appears, the text starts hidden and aria-expanded follows its state.

وا بکە بڕگەی دووەم پیشان بدات و بیشارێتەوە. بێ دەقەکە دەبێت دیار بمێنێتەوە؛ بە دەردەکەوێت، دەقەکە بە شاراوەیی دەست پێدەکات و aria-expanded دۆخەکەی پەیڕەو دەکات.

The HTML part of the pageبەشی HTMLـی لاپەڕەکەindex.htmlHTMLRuns in the browserلە ناو تۆڕگەڕ کار دەکات
<h2>Our bread</h2>
<p>Fresh naan and samoon every morning from 6 am.</p>
<button type="button" id="more-button" aria-expanded="false"
        aria-controls="more" hidden>More about our bread</button>
<p id="more">We bake with flour from a mill near Erbil, in a clay oven,
  and we sell what is left at half price after 8 pm.</p>
Hintئاماژە

Copy the menu example and change the names: more-button and more.

نموونەی مێنیوەکە کۆپی بکە و ناوەکان بگۆڕە: more-button و more.

Show answerوەڵامەکە پیشان بدە

The same pattern as the menu button: the HTML shows everything, the script shows the button and hides the text, and each click turns hidden and aria-expanded round.

هەمان شێوازی مێنیو: هەموو شتێک پیشان دەدات، پیشان دەدات و دەقەکە دەشارێتەوە و هەر کلیکێک hidden و aria-expanded پێچەوانە دەکاتەوە.

One possible script.jsscript.jsـێکی گونجاوscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const moreButton = document.querySelector("#more-button");
const more = document.querySelector("#more");

moreButton.hidden = false;   // JavaScript works: show the button
more.hidden = true;          // and hide the extra text

moreButton.addEventListener("click", () => {
  const willShow = more.hidden;
  more.hidden = !willShow;
  moreButton.setAttribute("aria-expanded", willShow);
});
ExerciseڕاهێنانA “large text” switchسویچێکی «دەقی گەورە»

Write script.js for this button: each click adds or removes the class big-text on the <html> element, and aria-pressed must match. The CSS is html.big-text { font-size: 125%; }.

script.js بۆ ئەم بنووسە: هەر کلیکێک کلاسی big-text بۆ <html> زیاد یان لادەبات و aria-pressed دەبێت یەکسان بێت. بریتییە لە html.big-text { font-size: 125%; }.

The HTML part of the pageبەشی HTMLـی لاپەڕەکەindex.htmlHTMLRuns in the browserلە ناو تۆڕگەڕ کار دەکات
<h1>Shilan's Bakery</h1>
<p>Fresh bread every morning.</p>
<button type="button" id="size-button" aria-pressed="false">Large text</button>
Hintئاماژە

document.documentElement is the <html> element.

document.documentElement <html>ـە.

Show answerوەڵامەکە پیشان بدە
One possible script.jsscript.jsـێکی گونجاوscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const sizeButton = document.querySelector("#size-button");

sizeButton.addEventListener("click", () => {
  const isBig = document.documentElement.classList.toggle("big-text");
  sizeButton.setAttribute("aria-pressed", isBig);
});
ExerciseڕاهێنانWarn when few characters are leftئاگادارکردنەوە کاتێک کەم نووسە ماوە

Change the characters-left script so that the counter turns red (class warn) when fewer than 10 characters are left, and back to normal otherwise.

«چەند ماوە» بگۆڕە بۆ ئەوەی بڕگەی #counter سوور ببێت (کلاسی warn) کاتێک کەمتر لە ⁦10⁩ ماوە و لە کاتەکانی تردا ئاسایی بێتەوە.

Hintئاماژە

Add one line inside updateCounter().

یەک دێڕ لەناو updateCounter() زیاد بکە.

Show answerوەڵامەکە پیشان بدە

classList.toggle() takes a second value: true adds the class and false removes it, so left < 10 decides.

classList.toggle() دووەم وەردەگرێت: true کلاسەکە زیاد دەکات و false لای دەبات، بۆیە left < 10 بڕیار دەدات.

One possible script.jsscript.jsـێکی گونجاوscript.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
const message = document.querySelector("#message");
const counter = document.querySelector("#counter");

function updateCounter() {
  const left = message.maxLength - message.value.length;
  counter.textContent = `${left} characters left`;
  counter.classList.toggle("warn", left < 10);   // add "warn" only when true
}

message.addEventListener("input", updateCounter);
updateCounter();
ExerciseڕاهێنانFind the three bugsسێ باگەکە بدۆزەرەوە

Clicking this button should add a cake to the basket, but nothing happens and the console shows a red error. Find the three bugs, and say which error message each one causes.

کلیککردن لەم دەبێت کێکێک بخاتە سەبەتەکەوە، بەڵام هیچ ڕوو نادات و سوور پیشان دەدات. سێ بدۆزەرەوە و بڵێ هەریەکەیان چ دروست دەکات.

index.htmlindex.htmlindex.htmlHTMLRuns in the browserلە ناو تۆڕگەڕ کار دەکات
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Order</title>
  <script src="order.js"></script>
</head>
<body>
  <button type="button" id="order">Order a cake</button>
  <p id="total">0 cakes in your basket</p>
</body>
</html>
order.jsorder.jsorder.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
let count = 0;
const button = document.querySelector("order");
const total = document.querySelector("#total");

button.addeventListener("click", () => {
  count = count + 1;
  total.textContent = count + " cakes in your basket";
});
Hintئاماژە

Read the error, fix one thing, reload, read again. Each fix can show the next error.

بخوێنەوە، یەک شت چاک بکە، دووپاتە باری بکەرەوە، دیسان بیخوێنەوە. هەر چاککردنێک لەوانەیە داهاتوو پیشان بدات.

Show answerوەڵامەکە پیشان بدە
  1. No defer on line 6 of index.html: the script runs in the <head> before the button exists. Add defer.
  2. querySelector("order") looks for an <order> element. Write "#order". These two bugs give Cannot read properties of null (reading 'addeventListener').
  3. addeventListener has a small e. When the first two are fixed, Chrome says button.addeventListener is not a function. Write addEventListener.
  1. defer نییە لە دێڕی 6ی index.html: پێش دروستبوونی لە <head>ـدا کار دەکات. defer زیاد بکە.
  2. querySelector("order") بەدوای <order>ـدا دەگەڕێت. بنووسە "#order". ئەم دوو Cannot read properties of null (reading 'addeventListener') دەدەن.
  3. addeventListener eـی بچووکی هەیە. کاتێک دووانەکەی یەکەم چاک کران، Chrome دەڵێت button.addeventListener is not a function. بنووسە addEventListener.
index.html, fixedindex.html، چاککراوindex.htmlHTMLRuns in the browserلە ناو تۆڕگەڕ کار دەکات
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Order</title>
  <script src="order.js" defer></script>
</head>
<body>
  <button type="button" id="order">Order a cake</button>
  <p id="total">0 cakes in your basket</p>
</body>
</html>
order.js, fixedorder.js، چاککراوorder.jsJAVASCRIPTRuns in the browserلە ناو تۆڕگەڕ کار دەکات
let count = 0;
const button = document.querySelector("#order");
const total = document.querySelector("#total");

button.addEventListener("click", () => {
  count = count + 1;
  total.textContent = `${count} cakes in your basket`;
});

Summaryپوختە

  • JavaScript is the behaviour layer: client-side code that reacts, changes the page, checks forms and fetches data.
  • Link script.js in the <head> with defer, or with type="module" through a web server; no onclick attributes.
  • The console shows console.log() messages and red errors with the file and line; null means nothing was found.
  • const for values that stay, let for values that change; template literals put values into text with ${…}.
  • The DOM is the page as a tree; querySelector() finds an element with a CSS selector; textContent, classList and hidden change it.
  • addEventListener() runs a function on every event: click → event → function → DOM → screen.
  • Keep ARIA in step: aria-pressed for a toggle button, aria-expanded for a menu button.
  • HTML checks first, JavaScript helps, the server always checks again.
  • Progressive enhancement: the page works with HTML alone, and JavaScript only makes it better.
  • چینی ڕەفتارە: کۆدی کە وەڵام دەداتەوە، لاپەڕەکە دەگۆڕێت، دەپشکنێت و دەهێنێت.
  • script.js لە <head>ـدا بە defer ببەستەرەوە، یان بە type="module" لە ڕێگەی ؛ onclick نا.
  • پەیامەکانی console.log() و لەگەڵ فایل و دێڕ پیشان دەدات؛ null واتە هیچ نەدۆزرایەوە.
  • const بۆ ئەو دەمێننەوە، let بۆ ئەوانەی دەگۆڕێن؛ template literal بە ${…} دەخاتە ناو دەقەوە.
  • لاپەڕەکەیە وەک ؛ querySelector() بە دەدۆزێتەوە؛ textContent، classList و hidden دەیگۆڕن.
  • addEventListener() لە هەموو جێبەجێ دەکات: کلیک ← ← ← DOM ← شاشە.
  • لەگەڵ دۆخەکەدا یەکسان بهێڵەرەوە: aria-pressed بۆ سویچ، aria-expanded بۆ مێنیو.
  • سەرەتا دەپشکنێت، یارمەتی دەدات، هەمیشە دووپاتە دەپشکنێتەوە.
  • : لاپەڕەکە تەنیا بە کار دەکات و تەنیا باشتری دەکات.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Static and Dynamic Websites and Website Typesلاپەڕەتۆڕە نەگۆڕەکان، لاپەڕەتۆڕە داینامیکەکان و جۆرەکانی تۆڕگە

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.