* chore(learn): audit basic algorithm scripting * chore(learn): audit basic data structures * chore(learn): audit basic javascript * chore(learn): audit debugging * chore(learn): audit es6 * chore(learn): audit functional programming * chore(learn): audit intermidate algorithms * chore(learn): audit js projects * chore(learn): audit object oriented programming * chore(learn): audit regex * fix(learn): remove stray . * fix(learn): string to code * fix(learn): missed some * fix(learn): clarify strings Based on Randy's feedback, clarifies string instances where quotes were removed in favour of back ticks. * fix: apply suggestions - thanks Randy! :) Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: non-suggestion comments * chore(learn): remove comments from codes Removes the comments from the description and instruction code blocks to ensure that all relevant information is translatable. * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: revert crowdin fix * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-arrays.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * fix: Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * chore: change voice * fix: Christopher Nolan * fix: expressions would evaluate * fix: will -> would * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix: to work to push * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops.md Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/object-oriented-programming/add-methods-after-inheritance.md Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Co-authored-by: Shaun Hamilton <51722130+ShaunSHamilton@users.noreply.github.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
		
			
				
	
	
		
			100 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ---
 | |
| id: 56533eb9ac21ba0edf2244c7
 | |
| title: Accessing Object Properties with Dot Notation
 | |
| challengeType: 1
 | |
| videoUrl: 'https://scrimba.com/c/cGryJs8'
 | |
| forumTopicId: 16164
 | |
| dashedName: accessing-object-properties-with-dot-notation
 | |
| ---
 | |
| 
 | |
| # --description--
 | |
| 
 | |
| There are two ways to access the properties of an object: dot notation (`.`) and bracket notation (`[]`), similar to an array.
 | |
| 
 | |
| Dot notation is what you use when you know the name of the property you're trying to access ahead of time.
 | |
| 
 | |
| Here is a sample of using dot notation (`.`) to read an object's property:
 | |
| 
 | |
| ```js
 | |
| var myObj = {
 | |
|   prop1: "val1",
 | |
|   prop2: "val2"
 | |
| };
 | |
| var prop1val = myObj.prop1;
 | |
| var prop2val = myObj.prop2;
 | |
| ```
 | |
| 
 | |
| `prop1val` would have a value of the string `val1`, and `prop2val` would have a value of the string `val2`.
 | |
| # --instructions--
 | |
| 
 | |
| Read in the property values of `testObj` using dot notation. Set the variable `hatValue` equal to the object's property `hat` and set the variable `shirtValue` equal to the object's property `shirt`.
 | |
| 
 | |
| # --hints--
 | |
| 
 | |
| `hatValue` should be a string
 | |
| 
 | |
| ```js
 | |
| assert(typeof hatValue === 'string');
 | |
| ```
 | |
| 
 | |
| The value of `hatValue` should be the string `ballcap`
 | |
| 
 | |
| ```js
 | |
| assert(hatValue === 'ballcap');
 | |
| ```
 | |
| 
 | |
| `shirtValue` should be a string
 | |
| 
 | |
| ```js
 | |
| assert(typeof shirtValue === 'string');
 | |
| ```
 | |
| 
 | |
| The value of `shirtValue` should be the string `jersey`
 | |
| 
 | |
| ```js
 | |
| assert(shirtValue === 'jersey');
 | |
| ```
 | |
| 
 | |
| You should use dot notation twice
 | |
| 
 | |
| ```js
 | |
| assert(code.match(/testObj\.\w+/g).length > 1);
 | |
| ```
 | |
| 
 | |
| # --seed--
 | |
| 
 | |
| ## --after-user-code--
 | |
| 
 | |
| ```js
 | |
| (function(a,b) { return "hatValue = '" + a + "', shirtValue = '" + b + "'"; })(hatValue,shirtValue);
 | |
| ```
 | |
| 
 | |
| ## --seed-contents--
 | |
| 
 | |
| ```js
 | |
| // Setup
 | |
| var testObj = {
 | |
|   "hat": "ballcap",
 | |
|   "shirt": "jersey",
 | |
|   "shoes": "cleats"
 | |
| };
 | |
| 
 | |
| // Only change code below this line
 | |
| 
 | |
| var hatValue = testObj;      // Change this line
 | |
| var shirtValue = testObj;    // Change this line
 | |
| ```
 | |
| 
 | |
| # --solutions--
 | |
| 
 | |
| ```js
 | |
| var testObj = {
 | |
|   "hat": "ballcap",
 | |
|   "shirt": "jersey",
 | |
|   "shoes": "cleats"
 | |
| };
 | |
| 
 | |
| var hatValue = testObj.hat;
 | |
| var shirtValue = testObj.shirt;
 | |
| ```
 |