← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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