← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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