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.

iAmOren
  • 2,760
  • 2
  • 11
  • 23
Codestudio
  • 525
  • 3
  • 5
  • 28
  • 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` – adiga Jul 01 '20 at 06:47
  • 1
    Object - with capital O, keys - plural - with s... – iAmOren Jul 01 '20 at 06:50
  • What happened to javascript?!? I will NEVER use `const` NOR `let` - ONLY `var`. – iAmOren Jul 01 '20 at 06:51
  • These suggestions worked. Thanks! – Codestudio Jul 01 '20 at 07:08

0 Answers0