← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 829 · 40 questions
TalentJR

Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".

NameDateTime takenScore ___ / 40
  1. 1.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <js> (c) <style> (d) <code>
  2. 2.⚡ What does this code show?
    let name = "Aman";
    alert("Welcome, " + name + "!");
    (a) name (b) Aman (c) Welcome, name! (d) Welcome, Aman!
  3. 3.⚡ What number does this code print?
    let a = 12;
    let b = 27;
    console.log(a + b);
  4. 4.⚡ Which word makes a new variable? (a) make (b) let (c) give (d) put
  5. 5.⚡ Which JavaScript word makes a new variable? (a) alert() (b) for (c) console.log() (d) let
  6. 6.⚡ Which JavaScript word writes in the console? (a) for (b) if (c) console.log() (d) alert()
  7. 7.⚡ Which JavaScript word shows a pop-up box? (a) if (b) console.log() (c) alert() (d) let
  8. 8.⚡ What number does this code print?
    let books = 14;
    books = books + 14;
    books = books - 15;
    console.log(books);
  9. 9.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 2;
    console.log(x + y);
    (a) 22 (b) Error (c) 4
  10. 10.⚡ What number does this code print?
    let coins = 7;
    coins = coins + 6;
    coins = coins - 10;
    console.log(coins);
  11. 11.⚡ What number does this code print?
    let a = 53;
    let b = 17;
    console.log(a - b);
  12. 12.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 5;
    console.log(x + y);
    (a) Error (b) 45 (c) 9
  13. 13.⚡ What number does this code print?
    let runs = 27;
    runs = runs + 13;
    runs = runs - 26;
    console.log(runs);
  14. 14.⚡ What number does this code print?
    let runs = 24;
    runs = runs + 13;
    runs = runs - 11;
    console.log(runs);
  15. 15.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hello, " + name + "!");
    (a) Hello, Kabir! (b) Hello, name! (c) Kabir (d) name
  16. 16.⚡ What number does this code print?
    let score = 8;
    score = score + 19;
    score = score - 24;
    console.log(score);
  17. 17.⚡ What number does this code print?
    let a = 23;
    let b = 6;
    console.log(a + b);
  18. 18.⚡ What number does this code print?
    let a = 8;
    let b = 10;
    console.log(a * b);
  19. 19.⚡ What number does this code print?
    let marks = 25;
    marks = marks + 7;
    marks = marks - 17;
    console.log(marks);
  20. 20.⚡ Which JavaScript word runs code when true? (a) for (b) alert() (c) if (d) let
  21. 21.⚡ What does this code show?
    let name = "Arjun";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) Arjun (c) name (d) Welcome, Arjun!
  22. 22.⚡ What number does this code print?
    let books = 11;
    books = books + 13;
    books = books - 16;
    console.log(books);
  23. 23.⚡ Where does console.log() show its output? (a) in the console (b) in the address bar (c) on the printer (d) on the title bar
  24. 24.⚡ What does JavaScript add to a web page? (a) the domain name (b) only colours (c) actions and changes (d) the page title
  25. 25.⚡ What number does this code print?
    let a = 24;
    let b = 4;
    console.log(a - b);
  26. 26.⚡ What does this code show?
    let name = "Arjun";
    console.log("Well done, " + name + "!");
    (a) Arjun (b) Well done, name! (c) Well done, Arjun! (d) name
  27. 27.⚡ Which JavaScript word repeats code? (a) for (b) let (c) if (d) console.log()
  28. 28.⚡ What number does this code print?
    let a = 6;
    let b = 13;
    console.log(a + b);
  29. 29.⚡ What number does this code print?
    let a = 13;
    let b = 18;
    console.log(a + b);
  30. 30.⚡ What number does this code print?
    let a = 6;
    let b = 32;
    console.log(a + b);
  31. 31.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .js (c) .html (d) .css
  32. 32.⚡ What number does this code print?
    let apples = 21;
    apples = apples + 14;
    apples = apples - 20;
    console.log(apples);
  33. 33.⚡ What number does this code print?
    let runs = 21;
    runs = runs + 5;
    runs = runs - 23;
    console.log(runs);
  34. 34.⚡ What does this code show?
    let name = "Riya";
    console.log("Well done, " + name + "!");
    (a) Riya (b) Well done, name! (c) Well done, Riya! (d) name
  35. 35.⚡ What number does this code print?
    let apples = 16;
    apples = apples + 9;
    apples = apples - 6;
    console.log(apples);
  36. 36.⚡ What number does this code print?
    let a = 36;
    let b = 34;
    console.log(a - b);
  37. 37.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 4;
    console.log(x + y);
    (a) 9 (b) Error (c) 54
  38. 38.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hi, " + name + "!");
    (a) name (b) Hi, Kabir! (c) Hi, name! (d) Kabir
  39. 39.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 3;
    console.log(x + y);
    (a) Error (b) 33 (c) 6
  40. 40.⚡ What number does this code print?
    let books = 26;
    books = books + 2;
    books = books - 7;
    console.log(books);

Answer key

  1. <script>
  2. Welcome, Aman!
  3. 39
  4. let
  5. let
  6. console.log()
  7. alert()
  8. 13
  9. 22
  10. 3
  11. 36
  12. 45
  13. 14
  14. 26
  15. Hello, Kabir!
  16. 3
  17. 29
  18. 80
  19. 15
  20. if
  21. Welcome, Arjun!
  22. 8
  23. in the console
  24. actions and changes
  25. 20
  26. Well done, Arjun!
  27. for
  28. 19
  29. 31
  30. 38
  31. .js
  32. 15
  33. 3
  34. Well done, Riya!
  35. 19
  36. 2
  37. 54
  38. Hi, Kabir!
  39. 33
  40. 21

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids