0
How do I write a sequence of numbers so I can define them as var's and use those var's to call strings?
As the title states, I want to input a number into my console.log to pull up a string. THis is what I had. Why didn't it work? function dayPlanner(num){ var num = 0>7; 0 = ::; 1 = ""; } console.log(0) *error*
2 Answers
+ 2
Variable names are not allowed to begin with a numeric character.
I think you need an array for this. Something like this?
var week = [];
for (let i = 0; i<7; i++){
week[i] = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"][i];
}
console.log(week[0]);
Or more simply:
var week = [];
week[0] = "Mon";
week[1] = "Tue";
.
.
.
console.log(week[0]); //Mon
+ 1
Thanks Russ! This is exactly what I was looking for. I'm going to study this and see what I can learn from it.