← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 44
  2. 57
  3. Hello, Kabir!
  4. a pop-up box
  5. .js
  6. Welcome, Zoya!
  7. 4
  8. 64
  9. 28
  10. actions and changes
  11. in the console
  12. 21
  13. 31
  14. console.log()
  15. let
  16. 6
  17. 24
  18. alert()
  19. 11
  20. Welcome, Zoya!
  21. 76
  22. for
  23. <script>
  24. 29
  25. if
  26. 68
  27. 24
  28. 57
  29. 86
  30. Hello, Riya!
  31. Hello, Aman!
  32. 34
  33. let
  34. 13
  35. 16
  36. 12
  37. 5
  38. 24
  39. Welcome, Meera!
  40. 44

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