Читайте также:
|
|
function guessNumber(number, clue) {
// Prompt the user for a number using the string value of clue
guess = prompt(clue);
// Convert their guess to a number using +
guess = +guess;
while (guess!== number) {
if (guess < number) {
guess = prompt("Too low. Guess again.");
}
else if (guess > number) {
guess = prompt("Too high. Guess again.");
}
guess = +guess;
}
console.log("You got it! The number was " + number);
}
guessNumber(36,"Pick a number between 1 and 100");
_____________________________________________________________________________________
// This evaluates to 'true'. This is because the first operand
// is true, so it is immediately returned. The second operand
// is never evaluated.
true || false;
// This evaluates to 'true'. This is because the first operand
// is false, so the second operand is returned. In this case,
// the second operand must be evaluated.
false || true;
// This evaluates to false. Since the first operand is false,
// the second operand is not even evaluated.
false && true;
// This evaluates to false. Since the first operand is true,
// the second operand is evaluated. Since this is false, the
// statement evaluates to false.
true && false;
• indexOf() Searches for the first occurrence of a character or substring.
• lastIndexOf() Searches for the last occurrence of a character or substring.
function contains(str, substr) {
if (str.indexOf(substr) >=0) {
return true;
}
else{
return false;
}
Дата добавления: 2015-08-17; просмотров: 41 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
ASSOCIATIVE ARRAYS | | | КАМЕНЬ, НОЖНИЦЫ, БУМАГА |