← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. for
  2. let
  3. 42
  4. 12
  5. Hi, Meera!
  6. 6
  7. a pop-up box
  8. 9
  9. <script>
  10. 12
  11. Welcome, Kabir!
  12. 36
  13. 25
  14. 13
  15. if
  16. console.log()
  17. 0
  18. 36
  19. .js
  20. Hello, Aman!
  21. 36
  22. 97
  23. alert()
  24. 0
  25. 8
  26. 9
  27. actions and changes
  28. 88
  29. Hello, Riya!
  30. 2
  31. 49
  32. 54
  33. 96
  34. Welcome, Aman!
  35. let
  36. in the console
  37. 99
  38. 8
  39. 17
  40. 7

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