Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function on Christmas day

Tags:

javascript

I'm having a little bit of trouble trying to make it 'snow' only on Christmas day. I figured out how to grab the day but I'm not sure how make it call SnowStorm() correctly.

var christmas = {
  month: 11,
  date: 25
}

function isItChristmas() {
  var now = new Date();
  var isChristmas = (now.getMonth() == christmas.month && now.getDate() == christmas.date);

if (isChristmas)
    return ;
  else
    return ;
}

var snowStorm = null;

function SnowStorm() {
    (snowstorm code)

}

snowStorm = new SnowStorm();

1 Answers

Here's the version if you are planning to make a function (not a class):

var christmas = {
  month: 12,
  date: 25
}

function isItChristmas() {
  var now = new Date();
  return (now.getMonth() == christmas.month && now.getDate() == christmas.date);
}

if (isItChristmas()){
    SnowStorm();
  }else{
    //not a christmas
}
    
function SnowStorm() {
    (snowstorm code)
}

Here's the one if you are planning to make a class:

var christmas = {
  month: 12,
  date: 25
}

function isItChristmas() {
  var now = new Date();
  return (now.getMonth() == christmas.month && now.getDate() == christmas.date);
}

var storm = new SnowStorm();

if (isItChristmas()){
    storm.Snow();
  }else{
    //not a christmas
}
    
function SnowStorm() {
    this.Snow = function(){
        (snowstorm code)
    }
}
like image 157
Sherzod Avatar answered Jan 25 '26 07:01

Sherzod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!