it's good to give helpful error messages so that the user knows why they are TERRIBLE.
this is the same ping pong language, but it gives helpful error messages if you write something wrong.
TRANSLATED:
it's easy to code a language with helpful error messages. it's [just] this:
function translate(text) {
if (text === "ping") {
return "pong"
} else if (text === "pong") {
return "ping"
} else {
throw new Error(`CRITICAL error: expected 'ping' or 'pong' but found '${text}'!`)
}
}
but now that your TRANSLATOR can error, you need to wrap it in a try catch thingy.
try {
result.textContent = translate(text)
result.style.color = "white"
} catch (error) {
result.textContent = error.message
result.style.color = "red"
}
back to the dream