← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 51
  3. Hi, Kabir!
  4. for
  5. if
  6. 99
  7. 5
  8. 89
  9. a pop-up box
  10. console.log()
  11. in the console
  12. 19
  13. 94
  14. 86
  15. <script>
  16. 19
  17. Well done, Aman!
  18. 32
  19. 38
  20. 35
  21. .js
  22. 23
  23. 33
  24. actions and changes
  25. 97
  26. 82
  27. 88
  28. Well done, Arjun!
  29. 26
  30. let
  31. 16
  32. Welcome, Meera!
  33. 83
  34. Hello, Arjun!
  35. 71
  36. Welcome, Riya!
  37. 54
  38. Well done, Riya!
  39. Hello, Aman!
  40. 64

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