w3resource

CoffeeScript: Find which 1st January be a Sunday between a range of years

CoffeeScript : Exercise-5 with Solution

Write a CoffeeScript program to find 1st January be a Sunday between 2015 and 2050.

Solution :

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="//jashkenas.github.io/coffee-script/extras/coffee-script.js"></script>
  <meta charset="utf-8">
  <title>Find  which 1st January be a Sunday between a range of years</title>
</head>
<body>

</body>
</html>

CoffeeScript Code :

console.log '--------------------'
year = 2015
while year <= 2050
  d = new Date(year, 0, 1)
  if d.getDay() == 0
    console.log '1st January is being a Sunday  ' + year
  year++
console.log '--------------------'

Sample Output:

"--------------------"
"1st January is being a Sunday  2017"
"1st January is being a Sunday  2023"
"1st January is being a Sunday  2034"
"1st January is being a Sunday  2040"
"1st January is being a Sunday  2045"
"--------------------"

Live Demo :

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


Improve this sample solution and post your code through Disqus.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/coffeescript-exercises/coffeescript-exercise-5.php