w3resource

CoffeeScript: Check whether a given year is a leap year in the Gregorian calendar

CoffeeScript: Exercise-3 with Solution

Write a CoffeeScript program to determine whether a given year is a leap year in the Gregorian calendar.

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>Check whether a given year is a leap year in the Gregorian calendar</title>
</head>
<body>

</body>
</html>

CoffeeScript Code :

year = window.prompt('Input a Year : ')
x = if year % 100 == 0 then year % 400 == 0 else year % 4 == 0
console.log x

Sample Output:

true

Live Demo :

See the Pen coffeescript-exercise-3 by w3resource (@w3resource) on CodePen.


Improve this sample solution and post your code through Disqus.