← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 842 · 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 = "1";
    let y = 8;
    console.log(x + y);
    (a) 18 (b) Error (c) 9
  2. 2.⚡ What number does this code print?
    let runs = 15;
    runs = runs + 17;
    runs = runs - 6;
    console.log(runs);
  3. 3.⚡ What number does this code print?
    let marks = 10;
    marks = marks + 19;
    marks = marks - 6;
    console.log(marks);
  4. 4.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 7;
    console.log(x + y);
    (a) 12 (b) Error (c) 57
  5. 5.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 5;
    console.log(x + y);
    (a) Error (b) 55 (c) 10
  6. 6.⚡ What does this code show?
    let name = "Meera";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) Welcome, Meera! (c) Meera (d) name
  7. 7.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 7;
    console.log(x + y);
    (a) Error (b) 17 (c) 8
  8. 8.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 7;
    console.log(x + y);
    (a) 47 (b) Error (c) 11
  9. 9.⚡ Which word makes a new variable? (a) let (b) give (c) put (d) make
  10. 10.⚡ What does this code show?
    let name = "Aman";
    console.log("Hi, " + name + "!");
    (a) Hi, name! (b) Aman (c) name (d) Hi, Aman!
  11. 11.⚡ Which JavaScript word shows a pop-up box? (a) let (b) alert() (c) for (d) console.log()
  12. 12.⚡ What number does this code print?
    let a = 37;
    let b = 14;
    console.log(a + b);
  13. 13.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .html (c) .jpg (d) .js
  14. 14.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 2;
    console.log(x + y);
    (a) 52 (b) 7 (c) Error
  15. 15.⚡ Where does console.log() show its output? (a) in the address bar (b) in the console (c) on the printer (d) on the title bar
  16. 16.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 3;
    console.log(x + y);
    (a) Error (b) 83 (c) 11
  17. 17.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 9;
    console.log(x + y);
    (a) Error (b) 19 (c) 10
  18. 18.⚡ What does this code show?
    let name = "Riya";
    alert("Welcome, " + name + "!");
    (a) Welcome, Riya! (b) name (c) Riya (d) Welcome, name!
  19. 19.⚡ Which JavaScript word writes in the console? (a) if (b) for (c) console.log() (d) alert()
  20. 20.⚡ What does this code show?
    let name = "Arjun";
    console.log("Well done, " + name + "!");
    (a) Well done, Arjun! (b) Arjun (c) Well done, name! (d) name
  21. 21.⚡ What number does this code print?
    let coins = 10;
    coins = coins + 8;
    coins = coins - 3;
    console.log(coins);
  22. 22.⚡ Which JavaScript word repeats code? (a) console.log() (b) alert() (c) if (d) for
  23. 23.⚡ What number does this code print?
    let runs = 11;
    runs = runs + 15;
    runs = runs - 4;
    console.log(runs);
  24. 24.⚡ What does this code print? (Look at the quotes!)
    let x = "9";
    let y = 7;
    console.log(x + y);
    (a) 16 (b) 97 (c) Error
  25. 25.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hello, " + name + "!");
    (a) Hello, name! (b) Hello, Kabir! (c) name (d) Kabir
  26. 26.⚡ What number does this code print?
    let a = 6;
    let b = 2;
    console.log(a * b);
  27. 27.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 9;
    console.log(x + y);
    (a) 13 (b) Error (c) 49
  28. 28.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 3;
    console.log(x + y);
    (a) 6 (b) 33 (c) Error
  29. 29.⚡ What number does this code print?
    let books = 13;
    books = books + 5;
    books = books - 1;
    console.log(books);
  30. 30.⚡ Which JavaScript word runs code when true? (a) let (b) if (c) for (d) console.log()
  31. 31.⚡ What number does this code print?
    let a = 48;
    let b = 9;
    console.log(a + b);
  32. 32.⚡ What number does this code print?
    let a = 7;
    let b = 4;
    console.log(a * b);
  33. 33.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 8;
    console.log(x + y);
    (a) 88 (b) 16 (c) Error
  34. 34.⚡ What number does this code print?
    let marks = 10;
    marks = marks + 6;
    marks = marks - 8;
    console.log(marks);
  35. 35.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <style> (c) <js> (d) <script>
  36. 36.⚡ What number does this code print?
    let marks = 5;
    marks = marks + 4;
    marks = marks - 2;
    console.log(marks);
  37. 37.⚡ What number does this code print?
    let runs = 6;
    runs = runs + 13;
    runs = runs - 1;
    console.log(runs);
  38. 38.⚡ 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
  39. 39.⚡ What number does this code print?
    let a = 8;
    let b = 28;
    console.log(a + b);
  40. 40.⚡ What number does this code print?
    let a = 24;
    let b = 15;
    console.log(a - b);

Answer key

  1. 18
  2. 26
  3. 23
  4. 57
  5. 55
  6. Welcome, Meera!
  7. 17
  8. 47
  9. let
  10. Hi, Aman!
  11. alert()
  12. 51
  13. .js
  14. 52
  15. in the console
  16. 83
  17. 19
  18. Welcome, Riya!
  19. console.log()
  20. Well done, Arjun!
  21. 15
  22. for
  23. 22
  24. 97
  25. Hello, Kabir!
  26. 12
  27. 49
  28. 33
  29. 17
  30. if
  31. 57
  32. 28
  33. 88
  34. 8
  35. <script>
  36. 7
  37. 18
  38. 95
  39. 36
  40. 9

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