Exercise 5: Write a Quote, name in variable: famous_person. Message in variable: message. Print it.

Опубликовано: 24 Октябрь 2024
на канале: TypeScript Insights
803
18

Here's the updated TypeScript code that stores the famous person's name in a variable and composes the message using the stored variables:

```typescript
const famous_person: string = "Albert Einstein";
const message: string = famous_person + ' once said, "A person who never made a mistake never tried anything new."';
console.log(message);
```

In this code, we create a variable called `famous_person` and assign the name of the famous person, "Albert Einstein", to it.

Then, we create another variable called `message` and compose the message by concatenating the `famous_person` variable with the quote using string concatenation (`+`) and including the necessary quotation marks and punctuation.

Finally, we use `console.log` to print the `message` variable, which contains the composed message, to the console.

When executed, this code will print the following message to the console:

```
Albert Einstein once said, "A person who never made a mistake never tried anything new."
```

The updated code allows for more flexibility by storing the famous person's name in a variable and composing the message using the stored variables.