← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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