← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 23
  2. alert()
  3. actions and changes
  4. for
  5. 95
  6. if
  7. 7
  8. 48
  9. 43
  10. Hi, Kabir!
  11. 40
  12. .js
  13. 3
  14. 26
  15. a pop-up box
  16. 33
  17. Hi, Kabir!
  18. 49
  19. 11
  20. let
  21. 11
  22. 5
  23. <script>
  24. console.log()
  25. in the console
  26. Well done, Riya!
  27. 2
  28. Hi, Zoya!
  29. 144
  30. Hello, Aman!
  31. 52
  32. 22
  33. let
  34. 33
  35. 41
  36. 15
  37. 4
  38. Well done, Aman!
  39. 36
  40. 36

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