← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 31
  3. if
  4. 87
  5. 23
  6. console.log()
  7. 84
  8. in the console
  9. 27
  10. 16
  11. 25
  12. <script>
  13. 44
  14. 38
  15. let
  16. let
  17. 17
  18. 93
  19. 21
  20. 23
  21. 88
  22. 10
  23. 56
  24. 25
  25. 46
  26. actions and changes
  27. 77
  28. for
  29. 82
  30. 26
  31. Welcome, Riya!
  32. a pop-up box
  33. 77
  34. 2
  35. Well done, Riya!
  36. Hi, Arjun!
  37. 1
  38. 83
  39. 92
  40. 25

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