Having problems with my code making my own method


#1



when I enter my code like this it works 

var newAge = function (yearsAlive) {
  
  yearsAlive = this.yearBorn + this.age ; 
  if (yearsAlive === 2016)  {
    
    console.log("That Sounds about right to me ! ");
    
  } else {
    
    console.log ("Your age cant be right , please try again");
  }
    
    
} ; 

var me = {
  
  name: "Markese" , 
  yearBorn: 1991, 
  age: 25,
  years: newAge
  
} ; 

me.years()



but when I try to enter my code like this with user input it doesnt work, I keep getting the else log "Your age cant be right , please try again " even if it is === 2016  what am I doing wrong ?


var userName = prompt("Whats your name?") ; 
var userBorn = prompt ("Hey " + userName + " What year where you born?") ; 
var userAge = prompt ("hmm so if you were born " + userBorn + " that would make you how old today?") ; 


var newAge = function () {
  
  yearsAlive = this.yearBorn + this.age ; 
  if (yearsAlive === 2016)  {
    
    console.log("That Sounds about right to me ! ");
    
  } else {
    
    console.log ("Your age cant be right , please try again");
  }
    
    
} ; 

var me = {
  
  name: userName , 
  yearBorn: userBorn, 
  age: userAge,
  years: newAge
  
} ; 

me.years() ;


#2

and I did add the yearsAlive into both functions still same problem


#3

Your prompt command stores the user input in a string format. So even if they type 2016 (no quotations), the prompt command saves it as "2016". If you change the value you are comparing to a string it should work:

if (yearsAlive == "2016") {
blah blah
}
else {
blah blah
}