+ 2

How do I set "black" equal to another variable name without changing it's meaning?

If I wanted to put it in a loop so i could have it repeat over again could I set "black" equal to a variable name and use numbers to make it repeat? https://code.sololearn.com/Wz0UmsSE0l9c/?ref=app

22nd Feb 2018, 9:38 PM
Babydoll Scripts
Babydoll Scripts - avatar
3 Respuestas
+ 3
function myFunc( mycolor){ var color= mycolor; switch(color){ case "red": document.write("Fiesty"); break; case "blue": document.write("Thoughtful"); break; default: document.write("Mystery"); } } for(i=0; i< 10; i++){ myFunc("black"); // write ur logic of passing color here }
22nd Feb 2018, 9:55 PM
Morpheus
Morpheus - avatar
+ 3
yep y not , enclose ur code in a function, with color value as argument, and call that function in a loop as many times as u want , passing different values
22nd Feb 2018, 9:52 PM
Morpheus
Morpheus - avatar
+ 3
Thank you so much. I never thought of using they function keyword.
22nd Feb 2018, 10:42 PM
Babydoll Scripts
Babydoll Scripts - avatar