Days until my birthday script

Discussion in 'JavaScript' started by zk0, Feb 19, 2007.

  1. #1
    Hi everyone!

    I need some help with this javascript. I just don't seem to understand how to code it properly.

    The code is suppose to let the user enter which month his birthday is on and which day, then the script would tell the user how many days it is until his birthday. But I don't know how to code that. This is what I need help with:

    I know that if I count todays ms seconds subtraction with the ms for the users birthday and then convert that to days I will know how many days it's left to the users birthday.

    This is the code I got so far:

    var minusEtt = Number( prompt('What month is your birthday (1-12)?','') );
    	var date = Number( prompt('What day is your birthday (1-31)?','') );
    
    	var month = minusEtt - 1 ; // the month - one
    
    var nextBirthday = new Date( month, date, 0, 0, 0, 0 ) // month, date, hour, min, sec, ms
    	
    	var todaysDate = new Date(); // Todays date
    Code (markup):
     
    zk0, Feb 19, 2007 IP
  2. zk0

    zk0 Peon

    Messages:
    299
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Okey, I have updated the code. It now looks like this. What have I done wrong that makes the code not to write out?

    	var minusEtt = Number( prompt('What month is your birthday (1-12)?','') );
    	var date = Number( prompt('What day is your birthday (1-31)?','') );
    
    	var month = minusEtt - 1 ; // the month - one
    
    	var nextBirthday = new Date( month, date, 0, 0, 0, 0 ) // month, date, hour, min, sec, ms
    	
    	var todaysDate = new Date(); // Todays date
    	
    	myDate.getTime();
    
    	var skillnad = nextBirthday.getTime() - todaysDate.getTime(); 
    	
    	var skrivUt = skillnad / 1000 / 60 / 60 / 24 ;
    	
    	document.write( skrivUt.toString( ) )
    Code (markup):
     
    zk0, Feb 19, 2007 IP
  3. zk0

    zk0 Peon

    Messages:
    299
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Anyone have any idea to why the script doesnt output days. Now it only outputs ms? :confused:
     
    zk0, Feb 20, 2007 IP
  4. zk0

    zk0 Peon

    Messages:
    299
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This problem is now solved! :D
     
    zk0, Feb 20, 2007 IP