Ninja homework2

by Olga Zhizhka

JavaScript

//Домашнее задание №2
// п.1
//Object square
var square = {
  size: 100,
  area: function(size) {
    var currentSize = size || this.size;
    return currentSize * 2;
  }
};
alert(square.area(500));
alert(square.area());

//Object flat
var flat = {
  countRoom: 3,
  totalArea: 100,
  balconyState: false,
  floor: 4
};
alert(flat.countRoom);
alert(flat.totalArea);
flat.balconyState = true;
alert(flat.balconyState);

//Object product
var product1 = {
  amount: 3,
  coast: 100,
  unitCoast: '$',
  saleState: true,
  salePercentage: 5,
  order: function(amount, saleState) {
    var currentAmount = amount || this.amount,
      currentSaleState = saleState || this.saleState,
      totalSum = (this.coast - this.coast * (this.salePercentage / 100)) * currentAmount;
    return ("Сумма Вашего заказа: " + totalSum + this.unitCoast);
  }
};
alert(product1.order());
alert(product1.order(1));

//Object user
var user = {
  firtName: 'Olga',
  lastName: 'Zhizhka',
  age: 33,
  password: 'q1w2e',
  occupation: 'frontend developer',
  say: function(text) {
    var currentText = text || "let's learn JS";
    return ('Hello my name is ' + this.firtName + ' and i say: "' + currentText + '"');
  }
};
alert(user.say());
alert(user.say('i have a dream'));

var animal = {
	breed: 'lion',
  name: 'King',
  weight: 130,
  say: function(){
  	alert('Rrrrr')
  }
}


//п.2
var player = {
	name: 'Alex',
  score: 1000,
  rank: 1
}

var book = {
	title: 'JavaScript: подробное руководство',
  author: 'David Flanagan',
  page: 900
}

var point = {
	coordX: 10,
  coordY: 20
}

var car = {
	color: 'white',
  brand: 'audi',
  year: 1996
}

//п.3
var lastNames = ['Ivanov', 'Petrov', 'Sidorov'];
var cars = ['Audi', 'BMW', 'Honda', 'Mersedes'];
var browsers = ['Google chrome', 'Opera', 'Firefox', 'Safari', 'Interent Explorer'];
var screen = [
	[1280, 1024],
  [1024, 768],
  [800, 600]
];

//п.4
var i, j = 0;
while( i < lastNames.length) {
	console.log(lastNames[i]);
  i++;
};
i = 0;

while( i <...