Читайте также:
|
|
// Declare and initialize myNumberArray
var myNumberArray = [];
// Populate it with numbers from 1 to 10
myNumberArray = [1,2,3,4,5,6,7,8,9,10];
// Declare and initialize myNumbers
var myNumbers = {
even: [],
odd: []
};
// Populate it according to parity
for (var i = 0; i < myNumberArray.length; i++) {
if (myNumberArray[i]%2 ===0) {
myNumbers.even.push(myNumberArray[i]);
} else {
myNumbers.odd.push(myNumberArray[i]);
}
}
// Log it to the console.
console.log(myNumbers);
_____________________________________________________________________________________
Number()
JavaScript has a built-in function called Number(). It converts the value in parentheses to a number that can be used in calculations. If it is not a number, it will return NaN (Not a Number).
_____________________________________________________________________________________
Return Object или конструктор объекта
function makeGamePlayer(name,totalScore,gamesPlayed) {
return {
"name": name,
"totalScore": totalScore,
"gamesPlayed": gamesPlayed
};
}
function addGameToPlayer(player,score) {
player.gamesPlayed++;
player.totalScore += score;
}
http://jsfiddle.net/WWFyA/ - посмотреть в чем дело.
_____________________________________________________________________________________
This. Vs Global Variables
// When a function is called in the global
// context, not as part of an object,
// `this` refers to the window - the global object
var x = 5;
function trickyThis() {
var x = 3;
alert(this.x);
}
// If we uncomment the next line, what would the alert say?
trickyThis();
// fill your answer in below:
var answer = 5;
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Дата добавления: 2015-08-17; просмотров: 36 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
КАМЕНЬ, НОЖНИЦЫ, БУМАГА | | | Горячие клавиши в LR |