← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. 69
  3. let
  4. 51
  5. 11
  6. 77
  7. 16
  8. in the console
  9. 11
  10. 61
  11. 4
  12. 68
  13. 38
  14. 22
  15. <script>
  16. a pop-up box
  17. 39
  18. Hi, Aman!
  19. .js
  20. actions and changes
  21. 3
  22. Hi, Riya!
  23. Well done, Riya!
  24. 7
  25. Hi, Meera!
  26. if
  27. alert()
  28. 20
  29. 47
  30. 97
  31. 12
  32. 22
  33. for
  34. 23
  35. let
  36. 5
  37. 43
  38. 10
  39. 6
  40. 74

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