Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Car = function(engine = 5, weight = 100, fuel = 1 , speed = 0, carValue = 1000) {
- this.engine = engine;
- this.weight = weight;
- this.fuel = fuel;
- this.speed = speed;
- this.damage = 1;
- this.carValue = carValue;
- };
- Car.prototype.race = function() {
- this.speed = this.engine/this.weight * this.fuel;
- this.fuel -= 0.2;
- }
- Car.prototype.refuel = function() {
- this.fuel = 1;
- }
- Car.prototype.crash = function() {
- this.damage = Math.floor(Math.random() * (100 - 0 + 1)) + 0;
- this.carValue -= 100 * this.damage;
- }
- Car.prototype.sell = function() {
- this.value = 100;
- }
- var mercedes = new Car();
- var honda = new Car();
- var volvo = new Car(1, 1000, 0.5);
- // Mercedes zaidejas nusipirko patobulinima
- mercedes.weight = 70;
- honda.race(); // 0,05 greitis
- mercedes.race(); // 0,07 greitis
- if(honda.speed > mercedes.speed) {
- console.log("honda laimejo");
- honda.race();
- volvo.race();
- } else {
- console.log("mercedes laimejo");
- mercedes.race();
- volvo.race();
- }
- volvo.crash();
- console.log(honda);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement