← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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