← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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