← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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