← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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