Search⌘ K

Solution Review: Rewriting Code as an Expression

Explore how to refactor imperative if/else code into concise expressions using ternary operators in TypeScript and JavaScript. Understand the syntax and practical application for more readable and functional-style code.

We'll cover the following...

Solution

The code provided below is the solution to the Rewriting Code as an Expression challenge.

TypeScript 3.3.4
function checkHealth(health: number) {
return health > 80 ? 'You are in good shape' : 'You should work out more!';
}
console.log(checkHealth(80));
...