I am trying to do this evolution thing with different characters and it is having an issue with the "if (perTable. + ("per" + per + 1) + .allele == "black")" part of the code. It throws unexpected identifier error whereas I thought everything was in the correct syntax. I'm new to code and would appreciate any easy fix for this.
I tried spreading out the plus signs by adding some spaces in between perTable
, ("per" + per + 1) bit, and also before the .allele but that didn't seem to help either.
Code:
var per = 0;
var perTable = {
per1: {
allele: "green",
number: "1",
living:"1",
},
per2: {
allele: "black",
number: "2",
living:"1",
}
};
// console.log(perTable.per2.number)
for (var i = 0; i < Object.keys(perTable).length; i++){
// console.log("per"+(per + 1))
if (perTable. + ("per" + per + 1) + .allele == "black"){
console.log("okay");
} else {
console.log("yikes");
}
per++;
};
I want it to log "okay" once and "yikes" once in console but instead I get unexpected identifier at line 19 and letter 16. If you could help that would be great!