+ 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
3 odpowiedzi
+ 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
}
+ 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
+ 3
Thank you so much. I never thought of using they function keyword.