← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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