← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 1
  2. Hello, Kabir!
  3. Hello, Kabir!
  4. Hi, Meera!
  5. console.log()
  6. 3
  7. 6
  8. actions and changes
  9. 9
  10. let
  11. 58
  12. if
  13. Welcome, Zoya!
  14. alert()
  15. 0
  16. Well done, Kabir!
  17. 26
  18. let
  19. <script>
  20. 25
  21. 44
  22. 88
  23. 91
  24. 21
  25. .js
  26. 35
  27. Hi, Riya!
  28. 16
  29. Welcome, Zoya!
  30. 15
  31. 16
  32. 5
  33. for
  34. 37
  35. 11
  36. 0
  37. 3
  38. Well done, Riya!
  39. 2
  40. 5

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