← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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