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*

16th Apr 2019, 6:13 PM
Jake Serrano
Jake Serrano - avatar
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
16th Apr 2019, 6:49 PM
Russ
Russ - avatar
+ 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.
17th Apr 2019, 2:08 PM
Jake Serrano
Jake Serrano - avatar