scrimba
Learn Typescript
Learn structural types
Array Types
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

AboutCommentsNotes
Array Types
Expand for more info
index.ts
run
preview
console
// Array Types
// Can you add a stayedAt property to the you Object, that contains places you
// have stayed as strings, then add the correct key with assigned type to the
// existing Object Type?

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

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: {
firstName: string;
lastName: string;
isReturning: boolean;
age: number;
} = {
firstName: 'Bobby',
lastName: 'Brown',
isReturning: true,
age: 35,
}


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

populateUser(you.isReturning, you.firstName)

Console
/index.html
-6:15