← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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