TypeScript bootcamp · Lab 09

Leap year

easyIf Else10 minLesson: If Else

Read the question, write TypeScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read a year. Print yes if it is a leap year, else no.

Leap years are divisible by 400, or by 4 but not by 100.

Input. One integer year.

Output. yes or no.

Examples

Example 1
Input
2000
Output
yes
Example 2
Input
1900
Output
no
Example 3
Input
2024
Output
yes
Hint
  1. (y % 400 === 0) || (y % 4 === 0 && y % 100 !== 0)
Show correct code

Peek only after you have tried. You can still Check your own version.

const y = Number(readLine());
const leap = y % 400 === 0 || (y % 4 === 0 && y % 100 !== 0);
console.log(leap ? 'yes' : 'no');
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.