← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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