← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Arjun!
  2. 22
  3. if
  4. actions and changes
  5. 48
  6. in the console
  7. for
  8. 4
  9. let
  10. 24
  11. <script>
  12. let
  13. 12
  14. 6
  15. a pop-up box
  16. 84
  17. 31
  18. .js
  19. 60
  20. Welcome, Arjun!
  21. 55
  22. 84
  23. 43
  24. 1
  25. 44
  26. 9
  27. 71
  28. 32
  29. 20
  30. 21
  31. alert()
  32. 22
  33. 7
  34. 25
  35. Welcome, Meera!
  36. 89
  37. Hi, Riya!
  38. 72
  39. 5
  40. 7

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