简体   繁体   中英

if statement doen't run even though the console.log before that shows the statement should run

I am trying to turn a javascript property true. I check first in the console if the if statement should run or not. According to, it should. I am sure I am doing something wrong but I don't know what.

In the console it is the same id.

$(document).click(function (e) {
//Selects the current HTMl element and gets its id
let questionId = $(e.target).parent().attr('id');

for (let i in wholeSurvey['formCategories']) {
    let cat = wholeSurvey['formCategories'][i];
    let catId = cat.id;

    for (let question in cat['formQuestions']) {
        question = cat['formQuestions'][question];
        console.error('question.id: ', question.id, 'questionId: ', questionId);

        if (question.id === questionId) {
            console.log('Hi');
            question.done = true;
            console.info(question);
        }
    }

    cat = wholeSurvey['formCategories'][i]['formQuestions'];

    if ($(cat).last()[0].done === true) {
        console.log($(cat).last());
        $("#A" + catId).css('background-color', '#46AD58').text('');
    }
  }
});

I expect it to turn the done properthy of question to true, but for now nothing changes and it entirely "skips" the if statement.

All help is welcome, sorry for grammar and spelling mistakes.

questionId was indeed a string like @Nick said in the comments. I used parseInt () to make questionId a number. I used this site: gomakethings.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM