← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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