scrimba
Learn Typescript
Learn primitive types
Type Assignment and Type Inference
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

Type Assignment and Type Inference
AboutCommentsNotes
Type Assignment and Type Inference
Expand for more info
index.ts
run
preview
console
// Type Assignment and Type Interference
// add a isOpen variable and assign it the boolean type

const returningUserDisplay = document.querySelector('#returning-user')
const userNameDisplay = document.querySelector('#user')
const reviewTotalDisplay = document.querySelector('#reviews')

const reviews = [
{
name: 'Sheia',
stars: 5,
loyaltyUser: true,
date: '01-04-2021'
},
{
name: 'Andrzej',
stars: 3,
loyaltyUser: false,
date: '28-03-2021'
},
{
name: 'Omar',
stars: 4,
loyaltyUser: true,
date: '27-03-2021'
},
]


function showReviewTotal(value: number, reviewer: string, isLoyalty: boolean) {
const iconDisplay = isLoyalty ? '⭐' : ''
reviewTotalDisplay.innerHTML = 'review total ' + value.toString() + '| last reviewed by ' + reviewer + ' ' + iconDisplay
}

showReviewTotal(reviews.length, reviews[0].name, reviews[0].loyaltyUser)


const you = {
userName: 'Bobby',
isReturning: true,
}


function populateUser(isReturning : boolean, userName: string ) {
if (isReturning){
returningUserDisplay.innerHTML = 'back'
}
userNameDisplay.innerHTML = userName
}

populateUser(you.isReturning, you.userName)
Console
/index.html
-5:57