← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. a pop-up box
  2. 45
  3. 66
  4. 6
  5. .js
  6. 44
  7. console.log()
  8. 6
  9. 23
  10. 10
  11. 17
  12. alert()
  13. Hello, Kabir!
  14. Hello, Meera!
  15. 21
  16. 16
  17. in the console
  18. 0
  19. if
  20. let
  21. Hi, Riya!
  22. let
  23. Welcome, Riya!
  24. 10
  25. 5
  26. 6
  27. 44
  28. 5
  29. 110
  30. Hello, Aman!
  31. 55
  32. 11
  33. 29
  34. 11
  35. 18
  36. 38
  37. 12
  38. 68
  39. Welcome, Zoya!
  40. 69

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