scrimba
Learn Typescript
Learn primitive types
Fixing the Website mini-challenge
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

Fixing the Website mini-challenge
AboutCommentsNotes
Fixing the Website mini-challenge
Expand for more info
index.ts
run
preview
console
// Fixing the Website

// Can you fix my code to show 'Welcome back Bobby' in the Nav Bar for
// our couch surfing website? Do this by assigning types to the parameters
// we pass to our populateUser function, so that we can be aware of
// errors in our user objects in the future.

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: {firstName: 'Bobby', lastName: 'Brown'},
isReturning: 'yes',
}


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

populateUser(you.userName, you.isReturning)

Console
/index.html
-5:12