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>
<head>
<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>
</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
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.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join