← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. if
  3. 11
  4. <script>
  5. 4
  6. 55
  7. 67
  8. 93
  9. let
  10. 27
  11. 5
  12. 75
  13. Hello, Aman!
  14. Welcome, Kabir!
  15. 0
  16. 22
  17. alert()
  18. 16
  19. 18
  20. 47
  21. .js
  22. let
  23. 95
  24. for
  25. 59
  26. 61
  27. 23
  28. Well done, Riya!
  29. in the console
  30. actions and changes
  31. 18
  32. 95
  33. 79
  34. Welcome, Zoya!
  35. 4
  36. 20
  37. 15
  38. 45
  39. 33
  40. 38

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