0
0
Javascriptprogramming~10 mins

If statement in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the number is positive.

Javascript
if (number [1] 0) {
  console.log('Positive number');
}
Drag options to blanks, or click blank then click option'
A>
B<
C===
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check for negative numbers instead.
Using '===' checks for equality, not greater than.
2fill in blank
medium

Complete the code to print 'Even' if the number is divisible by 2.

Javascript
if (number [1] 2 === 0) {
  console.log('Even');
}
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' will not check divisibility.
Using '*' multiplies numbers, not checks remainder.
3fill in blank
hard

Fix the error in the if statement to check if age is at least 18.

Javascript
if (age [1] 18) {
  console.log('Adult');
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' checks for younger than 18.
Using '==' checks only exactly 18, not older.
4fill in blank
hard

Fill both blanks to print 'Teenager' if age is between 13 and 19 inclusive.

Javascript
if (age [1] 13 && age [2] 19) {
  console.log('Teenager');
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for the first blank would exclude 13.
Using '>' for the second blank would exclude 19.
5fill in blank
hard

Fill the blanks to print 'Grade A' if score is above 90, 'Grade B' if score is above 80, else 'Grade C'.

Javascript
if (score [1] 90) {
  console.log('Grade A');
} else if (score [2] 80) {
  console.log('Grade B');
} else {
  console.log('Grade C');
}
Drag options to blanks, or click blank then click option'
A>
B>=
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' would include boundary scores incorrectly.
Using '<=' in the blanks would cause wrong grade assignments.