← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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