← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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