← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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