← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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