← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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