scrimba
21 web dev tips for 2021 🎇
Tip 6: TypeScript Part 1
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

To see this lesson you need to be logged in. Joining Scrimba is free and gives you access to 20+ courses.Sign up
AboutCommentsNotes
Tip 6: TypeScript Part 1
Expand for more info
index.ts
run
preview
console
// Introduction to TypeScript
// TypeScript Examples One

// Function written in vanilla JavaScript
// function subtract(a, b) {
// return a - b
// }

// subtract(6,4)

//Function written with TypeScript
// function subtract(a: number, b: number) {
// return a - b
// }

// subtract('6',4)

// Mini Challenge
// Pass the correct types to the following function to make the text
// appear in the text bubble.
function sendText (isLate: boolean, name: string, time: number) {
if (isLate) {
const textBubble = document.querySelector('.text-bubble')
textBubble.innerHTML = 'Hello ' + name + ', I am stuck in traffic, I should be there at ' + time + '.'
}
}
Console
/index.html
-5:33