← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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