← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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