← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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