← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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