← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 27
  3. let
  4. Welcome, Meera!
  5. 70
  6. 4
  7. 81
  8. console.log()
  9. 20
  10. for
  11. 11
  12. Hi, Kabir!
  13. 16
  14. 13
  15. 78
  16. Hi, Arjun!
  17. in the console
  18. 19
  19. 57
  20. 22
  21. let
  22. 41
  23. a pop-up box
  24. 73
  25. actions and changes
  26. 5
  27. Hello, Arjun!
  28. Hi, Aman!
  29. 53
  30. 11
  31. 28
  32. 48
  33. 11
  34. Welcome, Arjun!
  35. 18
  36. if
  37. Welcome, Aman!
  38. 49
  39. 4
  40. Welcome, Riya!

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