scrimba
Основы JavaScript
Смешивание и сопоставление массивов c объектами
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Смешивание и сопоставление массивов c объектами
AboutCommentsNotes
Смешивание и сопоставление массивов c объектами
Expand for more info
index.js
run
preview
console
var questions = [
['Сколько континетов на планете Земля?', 7],
['Сколько стран в мире?', 197],
['Сколько из них находятся в Северной Америке?', 23]
];

var correctAnswers = 0;
var question;
var answer;
var response;

function print(message) {
document.write(message);
}

for (var i = 0; i < questions.length; i += 1) {
question = questions[i][0];
answer = questions[i][1];
response = prompt(question);
response = parseInt(response);

if (response === answer) {
correctAnswers += 1;
}
}

html = "Вы угадали правильно только " + correctAnswers + " вопрос(ов)."
print(html);
Console
index.html
-3:04