← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 7
  2. 97
  3. 53
  4. 10
  5. 97
  6. alert()
  7. 0
  8. actions and changes
  9. 58
  10. Hi, Riya!
  11. in the console
  12. 4
  13. if
  14. Hello, Aman!
  15. for
  16. let
  17. 24
  18. 5
  19. 21
  20. Welcome, Meera!
  21. 26
  22. 9
  23. 17
  24. console.log()
  25. 53
  26. 5
  27. 81
  28. 71
  29. <script>
  30. 21
  31. let
  32. 64
  33. Well done, Zoya!
  34. 18
  35. Well done, Riya!
  36. 15
  37. 5
  38. 33
  39. 42
  40. 18

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