← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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