← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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