← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. actions and changes
  2. 26
  3. 49
  4. 21
  5. alert()
  6. 10
  7. in the console
  8. let
  9. Hello, Kabir!
  10. Hi, Riya!
  11. <script>
  12. 47
  13. 84
  14. Hello, Zoya!
  15. let
  16. 35
  17. 22
  18. 85
  19. 65
  20. 2
  21. 53
  22. a pop-up box
  23. 32
  24. 41
  25. 21
  26. 36
  27. Welcome, Aman!
  28. Hello, Zoya!
  29. Hello, Meera!
  30. console.log()
  31. 95
  32. 45
  33. 10
  34. 91
  35. if
  36. 77
  37. 51
  38. 94
  39. 83
  40. for

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