So Im very new to ES6 and would love to know if there is a simpler way to return the string than having to try and figure out the order, I enjoy this method but I find that with large strings its quite a bit of torture. Please can anyone shoot me in the right direction ? Also Is it possible to use Arrow function for this function ?
function text(strings, ...values){
if(values[3]>200){
values[2] = "realy fast up too"
}else{
values[2] = "super slow up too"
}
return `${strings[0]}${values[0]} ${values[1]}${strings[1]}${strings[2]}${values[2]} ${values[3]}${strings[3]}${strings[4]}${strings[5]}${values[4]}`;
}
let sentance = text`Your ${this.color} ${this.cartype}can drive ${""} ${this.speed}Km/H while going ${this.carsound(carS)}`;
Also I tried using an arrow function like this below but I get an compile error (Unexpected token) on line 16 which is the first line you see
text(strings, ...values)=>{
if(values[3]>200){
values[2] = "realy fast up too"
}else{
values[2] = "super slow up too"
}
return `${strings[0]}${values[0]} ${values[1]}${strings[1]}${strings[2]}${values[2]} ${values[3]}${strings[3]}${strings[4]}${strings[5]}${values[4]}`;
}
let text = (strings, ...values) => ...