0
0
Javascriptprogramming~20 mins

Object use cases in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Object use cases
πŸ“– Scenario: You are building a simple contact list app. Each contact has a name and a phone number. You want to store these contacts in an object for easy lookup and management.
🎯 Goal: Create an object to store contacts, add a new contact, retrieve a contact's phone number, and display the contact list.
πŸ“‹ What You'll Learn
Create an object called contacts with two contacts and their phone numbers.
Create a variable called newContactName with the value 'Emma' and a variable called newContactNumber with the value '555-0199'.
Add the new contact to the contacts object using the variables newContactName and newContactNumber.
Use a for...in loop to print each contact's name and phone number in the format: Name: PhoneNumber.
πŸ’‘ Why This Matters
🌍 Real World
Objects are used to store and manage related data like contacts, products, or settings in many apps.
πŸ’Ό Career
Understanding objects and how to manipulate them is essential for web development and working with data in JavaScript.
Progress0 / 4 steps
1
Create the initial contacts object
Create an object called contacts with these exact entries: 'Alice': '555-1234' and 'Bob': '555-5678'.
Javascript
Need a hint?

Use curly braces {} to create an object and add key-value pairs for Alice and Bob.

2
Add new contact variables
Create a variable called newContactName with the value 'Emma' and a variable called newContactNumber with the value '555-0199'.
Javascript
Need a hint?

Use const to create variables for the new contact's name and number.

3
Add the new contact to the contacts object
Add the new contact to the contacts object using the variables newContactName and newContactNumber.
Javascript
Need a hint?

Use bracket notation with the variable newContactName to add the new contact to the object.

4
Print all contacts
Use a for...in loop with the variable name to print each contact's name and phone number in the format: Name: PhoneNumber.
Javascript
Need a hint?

Use for (const name in contacts) and console.log with template strings to print each contact.