Sum of Arguments

by Santosh Suresh

HTML

<script src="https://searls.github.io/jasmine-all/jasmine-all-min.js"></script>
<h1>Constructor Functions</h1>
<ul>
  <li><b>new</b> keyword is special</li>
  <li>Every object has a <i>prototype</i></li>
</ul>

<h2>Exercises</h2>
<ul>
  <li>Add <i>numberOfGears</i> to return 5 by default</li>
</ul>

JavaScript

function Vehicle(name, year) {
  this.name = name;
  this.year = year;
}

Vehicle.prototype.getName = function() {
  return this.name;
}

Vehicle.prototype.toString = function() {
  return this.name + " - " + this.year;
}

var santro = new Vehicle("Santro", 2001);
var swift = new Vehicle("Swift", 2013);

swift.toString = function() {
  return this.year + " was when " + this.name + " was bought";
}

swift.isAutomatic = function() {
  return false;
}


describe("Vehicle constructor", function() {
  it("should have Santro as the name", function() {
    expect(santro.toString()).toBe("Santro - 2001");
  });

  it("should have Vehicle as the constructor", function() {
    expect(santro.constructor).toBe(Vehicle)
  });

  it("swift should have its owne toString function", function() {
    expect(swift.toString()).toBe("2013 was when Swift was bought")
  });

  it("swift should have a isAutomatic function", function() {
    expect(santro.isAutomatic).toBe(undefined);
    expect(swift.isAutomatic()).toBeFalsy()
  });
  
  it("return the number of gears", function(){
  	expect(santro.numberOfGears).toBe(5);
    expect(swift.numberOfGears).toBe(5);
  })
  

})