← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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