← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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