← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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