← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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