Я добавил комментарии в середине кода. Пожалуйста, помогите мне. Если вы можете, я должен доставить товар сегодня.
if (a === 3) { //this would be how many of the answers further the action
var starting = 2; // for an example: yes or no; two of the answers go to no, one goes to yes.
// we take 2 as a starting point /you can set these individually for each scenario;
if (starting === 2) {
for (i = 0; i < starting; i++) {
answers[i] = 1; //sets the two checking points of the answer to the no, remaining yes;
document.getElementById("btn" + i).style.backgroundColor = "red";
// the problem lies here
// I tried multiple ways but none of them worked so far
//i want to apply the style change to multiple buttons at once.
}
alert(answers);
for (i = 0; i < starting; i++) {
if (answers[i] == 1) {
}
}
}
}
Проблема в том, что имя кнопки, которая называется btn, и кнопки называются btn1, btn2, btn3; Я хочу, чтобы цикл for изменил его на все кнопки, однако строковый литерал в id не распознает i;
Пример: "btn" + i; = изменить стиль btn1
Я исправил это, ребята. Ошибка состояла в том, что цикл for начинается с 1;
И я назвал идентификатор кнопок неправильно. Начинающая ошибка! :)