Exercise 8: Create four lines. Output should be four lines and number 8 appearing once on each line.

Опубликовано: 02 Апрель 2026
на канале: TypeScript Insights
854
17

exercise8:
Code: https://github.com/typescriptkamran/e...

This TypeScript code is a simple script that outputs four lines with the number 8 appearing once on each line, separated by lines of underscores for visual clarity. The purpose of using the seperator variable is to define a string containing underscores (i.e., "_") repeated 80 times, which acts as a separator between each line of output.

Here's the explanation of each part of the code:

let seperator = "_": This line declares a variable seperator and assigns the string value "_" to it. The variable will be used to store the separator string containing underscores.

console.log(seperator.repeat(80)): This line outputs 80 underscores on the console. The repeat() method of the seperator string repeats the "_" character 80 times, creating a line of underscores.

console.log(5 + 3): This line outputs the result of the arithmetic expression 5 + 3, which is 8, on the console.

console.log(seperator.repeat(80)): This line outputs another line of 80 underscores on the console, acting as a separator between the previous output and the next one.

console.log(16 - 8): This line outputs the result of the arithmetic expression 16 - 8, which is 8, on the console.

console.log(seperator.repeat(80)): This line outputs another line of 80 underscores on the console.

console.log(4 * 2): This line outputs the result of the arithmetic expression 4 * 2, which is 8, on the console.

console.log(seperator.repeat(80)): This line outputs another line of 80 underscores on the console.

console.log(16 / 2): This line outputs the result of the arithmetic expression 16 / 2, which is 8, on the console.

console.log(seperator.repeat(80)): This line outputs a final line of 80 underscores on the console.

So, when you run this TypeScript code, you will see four lines with the number 8 appearing once on each line, separated by lines of underscores for visual distinction.