0

I have the following object called checkObj. I'm trying to use a for... in loop to see if the object contains the property foundNum. Since it does exist, the purpose of the program is to then reassign the value of "found" to 1 as shown below.

    const checkObj = {
      oddNum: 1,
      evenNum: 2,
      foundNum: 5,
      randomNum: 18
    };
    
    let found = 0;
    // ADD CODE HERE
    
    for (foundNum in checkObj) {
      if (object.key(checkObj).includes = foundNum ) {
        let found = 1
      }
    }

However, I get the following error: Reference Error on line 11: foundNum is not defined. I'm not very familiar with for... in loops so not sure how to fix this bug.

4
  • 1
    1) You are missing a let in let foundNum in checkObj. 2) You are redeclaring let found = 1 Remove let here. 3) includes is a function. You don't need a loop here. You can just do: checkObj.hasOwnProperty("foundNum") or "foundNum" in checkObj Commented Jul 1, 2020 at 6:47
  • 1
    Object - with capital O, keys - plural - with s... Commented Jul 1, 2020 at 6:50
  • What happened to javascript?!? I will NEVER use const NOR let - ONLY var. Commented Jul 1, 2020 at 6:51
  • These suggestions worked. Thanks! Commented Jul 1, 2020 at 7:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.