← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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