← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. console.log()
  2. Welcome, Meera!
  3. 26
  4. in the console
  5. for
  6. if
  7. Hello, Kabir!
  8. let
  9. 56
  10. 52
  11. 73
  12. 20
  13. 20
  14. a pop-up box
  15. 22
  16. let
  17. Hello, Kabir!
  18. alert()
  19. Well done, Zoya!
  20. 63
  21. 72
  22. 5
  23. 86
  24. actions and changes
  25. 51
  26. 26
  27. 40
  28. 13
  29. 40
  30. 92
  31. 18
  32. 45
  33. 10
  34. Hello, Zoya!
  35. 38
  36. 62
  37. 8
  38. 108
  39. 5
  40. <script>

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