← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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