w3resource logo


CoffeeScript exercises

CoffeeScript : Calculate number of days left until next Christmas

CoffeeScript : Exercise-7 with Solution

Write a CoffeeScript program to calculate days left until next Christmas.

Solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

</body>
</html>

CoffeeScript Code :

today = new Date
cmas = new Date(today.getFullYear(), 11, 25)
if today.getMonth() == 11 and today.getDate() > 25
  cmas.setFullYear cmas.getFullYear() + 1
one_day = 1000 * 60 * 60 * 24
alert Math.ceil((cmas.getTime() - today.getTime()) / one_day) + ' days left until Christmas!'

Live Demo :

JS Bin on jsbin.com

Post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program