Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript whats wrong with this funtion?

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #153739
    javascriptnewbie
    Participant

    var sam=new Object();
    sam.color=”red”;
    sam.height= function(a+b){
    return a+b;
    }
    document.write(sam.height(10,11));

    Please.

    #153746
    __
    Participant

    you can’t use + in the function parameter list. you need to use a comma , to separate them.

    var sam=new Object();
    sam.color="red";
    sam.height= function( a,b ){
        return a+b;
    }
    
    #153747
    Alen
    Participant
    #153749
    Alen
    Participant
    function Mph(miles, hours){
      this.miles = miles;
      this.hours = hours;
      this.milesPerHour = milesPerHour;
    }
    
    function milesPerHour(){
      return this.miles / this.hours;
    }
    
    var car1 = new Mph(100, 2);
    alert(car1.milesPerHour()); // 50
    

    Another way of doing it.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.