← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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