← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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