← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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