← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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