← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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