← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Aman!
  2. 18
  3. Well done, Kabir!
  4. <script>
  5. 120
  6. alert()
  7. actions and changes
  8. in the console
  9. 9
  10. 77
  11. console.log()
  12. Hi, Aman!
  13. 21
  14. let
  15. a pop-up box
  16. let
  17. 14
  18. 19
  19. 49
  20. if
  21. .js
  22. Welcome, Arjun!
  23. 27
  24. 33
  25. Well done, Kabir!
  26. 26
  27. 12
  28. 9
  29. 8
  30. 41
  31. 88
  32. 72
  33. for
  34. 43
  35. 42
  36. 23
  37. 61
  38. Welcome, Meera!
  39. 62
  40. 36

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