Honestly I don’t really understand what you’re trying to achieve but I’m guessing that you want to find out how to do your commands 3 times without writing the code 3 times.
I’d recommend putting those 3 var
s into an array and iterating through them with a for
-loop (for-loops). Hopefully this is what you wanted
let one
let two
let three
const numbers = [one, two, three]
for (i = 0; i < numbers.length; i++) {
if (numbers[i]) {
numbers[i] = "✔";
} else {
numbers[i] = "×";
}
}
Or using the map-function:
const one = true;
const two = false;
const three = true;
const numbers = [one, two, three];
const [newOne, newTwo, newThree] = numbers.map(x => x ? '✔' : '×');
3
solved 3 Variables into one function javascript? ´Variables are true or false and depending on the outcome I change it to the string [closed]