#963. Reverse a word
When the green flag is clicked, this script runs. What will the cat say?
when green flag clicked set [word v] to [tree] set [result v] to [] set [i v] to (length of (word)) repeat (length of (word)) set [result v] to (join (result) (letter (i) of (word))) change [i v] by (-1) end say (result)
# When the green flag is clicked
word = "tree"
result = ""
i = len(str(word))
for _ in range(len(str(word))):
result = str(result) + str((str(word))[i - 1])
i -= 1
print(result)
let word = 0, result = 0, i = 0;
// When the green flag is clicked
word = "tree";
result = "";
i = String(word).length;
for (let j = 0; j < String(word).length; j++) {
result = String(result) + String((String(word))[i - 1]);
i -= 1;
}
console.log(result);
💡 Not sure? Build it in Scratch and try it out.