I am trying to simplify mainly the if statements. As you can see, I colorize my text and this way works, but there is a lot of repetitive code in the if statements. Any help would be appreciated, thank you.
const colorText = ( message, colorr ) => {
let mesge = []
for (let i = 0; i < message.length; i++){
//TRYING TO SIMPLIFY THIS CODE BELOW\\//TRYING TO SIMPLIFY THIS CODE BELOW\\
//TRYING TO SIMPLIFY THIS CODE BELOW\\//TRYING TO SIMPLIFY THIS CODE BELOW\\
if(i===0 || i===5 || i===10 || i===15 || i===20) {colorr[i] = colorr[0]}
if(i===1 || i===6 || i===11 || i===16 || i===21) {colorr[i] = colorr[1]}
if(i===2 || i===7 || i===12 || i===17 || i===22) {colorr[i] = colorr[2]}
if(i===3 || i===8 || i===13 || i===18 || i===23) {colorr[i] = colorr[3]}
if(i===4 || i===9 || i===14 || i===19 || i===24) {colorr[i] = colorr[4]}
mesge[i] = (
<span style=>
{message[i]}
</span>
)
}
return mesge
// console.log(message)
// console.log(color)
}
Aucun commentaire:
Enregistrer un commentaire