← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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