← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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