mardi 24 juillet 2018

Javascript if else loop?

I'm sure there probably is, however I'm not sure what it's called so apologises if this is something super similar. I'm wondering if there's a faster way to code the following:

var b = "#ff0002";
var o = "#46c029";
var i = "#f2ec00";
var n = "#f64c98";
var g = "#52c6f3";

if(a==1){
    return b;
}else if(a==2){
    return o;
}else if(a==3){
    return i;
}else if(a==4){
    return n;
}else if(a==5){
    return g;
}

Aucun commentaire:

Enregistrer un commentaire