I am console logging a string using a for loop
and appending the for loop index number to each string. However, if the string matches the variable name roastAboutCheapLvl1
that I have defined, I want the variable content to be displayed instead.
What I have tried so far:
var roastAboutCheapLvl1 = "it works";
for (var i = 1; i <= 5; i++) {
var num = [i].toString();
var a = "roastAboutCheapLvl" + num;
console.log(a);
}
What I expected:
it works
roastAboutCheapLvl2
roastAboutCheapLvl3
roastAboutCheapLvl4
roastAboutCheapLvl5
What am I doing wrong in the above attempt?