← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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