2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 56bbb991ad1ed5201cd392d1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Updating Object Properties
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 1
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Description
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'description' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								After you've created a JavaScript object, you can update its properties at any time just like you would update any other variable. You can use either dot or bracket notation to update.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example, let's look at < code > ourDog< / code > :
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< blockquote > var ourDog = {< br >     "name": "Camper",< br >     "legs": 4,< br >     "tails": 1,< br >     "friends": ["everything!"]< br > };< / blockquote >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Since he's a particularly happy dog, let's change his name to "Happy Camper". Here's how we update his object's name property:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< code > ourDog.name = "Happy Camper";< / code >  or 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< code > ourDog["name"] = "Happy Camper";< / code >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Now when we evaluate < code > ourDog.name< / code > , instead of getting "Camper", we'll get his new name, "Happy Camper".
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Instructions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'instructions' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Update the < code > myDog< / code >  object's name property. Let's change her name from "Coder" to "Happy Coder". You can use either dot or bracket notation.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Tests
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'tests' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```yml
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								tests:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  text: Update < code > myDog</ code > ' s < code > "name"</ code >  property to equal "Happy Coder".
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(/happy coder/gi.test(myDog.name), 'Update < code > myDog< / code > ' s < code > "name"< / code >  property to equal "Happy Coder".');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: Do not edit the < code > myDog</ code >  definition
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: 'assert(/"name": "Coder"/.test(code), ''Do not edit the < code > myDog< / code >  definition'');'
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Challenge Seed
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'challengeSeed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'js-seed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Example
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var ourDog = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "name": "Camper",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "legs": 4,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "tails": 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "friends": ["everything!"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ourDog.name = "Happy Camper";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Setup
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var myDog = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "name": "Coder",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "legs": 4,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "tails": 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "friends": ["freeCodeCamp Campers"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Only change code below this line.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### After Test
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'js-teardown' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								(function(z){return z;})(myDog);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Solution
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'solution' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var myDog = {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "name": "Coder",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "legs": 4,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "tails": 1,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "friends": ["freeCodeCamp Campers"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								myDog.name = "Happy Coder";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >