﻿ CoffeeScript: Calculate number of days left until next Christmas - w3resource

# 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.

HTML Code :

``````<!DOCTYPE html>
<html>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
<meta charset="utf-8">
<title>Calculate number of days left until next Christmas</title>
<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
console.log Math.ceil((cmas.getTime() - today.getTime()) / one_day) + ' days left until Christmas!'
``````

Sample Output:

```"280 days left until Christmas!"
```

Live Demo :

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

Improve this sample solution and post your code through Disqus.

﻿