.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
access-array-data-with-indexes.english.md
access-multi-dimensional-arrays-with-indexes.english.md
accessing-nested-arrays.english.md
accessing-nested-objects.english.md
accessing-object-properties-with-bracket-notation.english.md
accessing-object-properties-with-dot-notation.english.md
accessing-object-properties-with-variables.english.md
add-new-properties-to-a-javascript-object.english.md
add-two-numbers-with-javascript.english.md
adding-a-default-option-in-switch-statements.english.md
appending-variables-to-strings.english.md
assignment-with-a-returned-value.english.md
build-javascript-objects.english.md
chaining-if-else-statements.english.md
comment-your-javascript-code.english.md
comparison-with-the-equality-operator.english.md
comparison-with-the-greater-than-operator.english.md
comparison-with-the-greater-than-or-equal-to-operator.english.md
comparison-with-the-inequality-operator.english.md
comparison-with-the-less-than-operator.english.md
comparison-with-the-less-than-or-equal-to-operator.english.md
comparison-with-the-strict-equality-operator.english.md
comparison-with-the-strict-inequality-operator.english.md
comparisons-with-the-logical-and-operator.english.md
comparisons-with-the-logical-or-operator.english.md
compound-assignment-with-augmented-addition.english.md
compound-assignment-with-augmented-division.english.md
compound-assignment-with-augmented-multiplication.english.md
compound-assignment-with-augmented-subtraction.english.md
concatenating-strings-with-plus-operator.english.md
concatenating-strings-with-the-plus-equals-operator.english.md
constructing-strings-with-variables.english.md
count-backwards-with-a-for-loop.english.md
counting-cards.english.md
create-decimal-numbers-with-javascript.english.md
declare-javascript-variables.english.md
declare-string-variables.english.md
decrement-a-number-with-javascript.english.md
delete-properties-from-a-javascript-object.english.md
divide-one-decimal-by-another-with-javascript.english.md
divide-one-number-by-another-with-javascript.english.md
escape-sequences-in-strings.english.md
escaping-literal-quotes-in-strings.english.md
find-the-length-of-a-string.english.md
finding-a-remainder-in-javascript.english.md
generate-random-fractions-with-javascript.english.md
generate-random-whole-numbers-with-javascript.english.md
generate-random-whole-numbers-within-a-range.english.md
global-scope-and-functions.english.md
global-vs.-local-scope-in-functions.english.md
golf-code.english.md
increment-a-number-with-javascript.english.md
initializing-variables-with-the-assignment-operator.english.md
introducing-else-if-statements.english.md
introducing-else-statements.english.md
iterate-odd-numbers-with-a-for-loop.english.md
iterate-through-an-array-with-a-for-loop.english.md
iterate-with-javascript-do...while-loops.english.md
iterate-with-javascript-for-loops.english.md
iterate-with-javascript-while-loops.english.md
local-scope-and-functions.english.md
logical-order-in-if-else-statements.english.md
manipulate-arrays-with-pop.english.md
manipulate-arrays-with-push.english.md
manipulate-arrays-with-shift.english.md
manipulate-arrays-with-unshift.english.md
manipulating-complex-objects.english.md
modify-array-data-with-indexes.english.md
multiple-identical-options-in-switch-statements.english.md
multiply-two-decimals-with-javascript.english.md
multiply-two-numbers-with-javascript.english.md
nest-one-array-within-another-array.english.md
nesting-for-loops.english.md
passing-values-to-functions-with-arguments.english.md
practice-comparing-different-values.english.md
profile-lookup.english.md
quoting-strings-with-single-quotes.english.md
record-collection.english.md
replacing-if-else-chains-with-switch.english.md
return-a-value-from-a-function-with-return.english.md
return-early-pattern-for-functions.english.md
returning-boolean-values-from-functions.english.md
selecting-from-many-options-with-switch-statements.english.md
shopping-list.english.md
stand-in-line.english.md
store-multiple-values-in-one-variable-using-javascript-arrays.english.md
storing-values-with-the-assignment-operator.english.md
subtract-one-number-from-another-with-javascript.english.md
testing-objects-for-properties.english.md
understand-string-immutability.english.md
understanding-boolean-values.english.md
understanding-case-sensitivity-in-variables.english.md
understanding-undefined-value-returned-from-a-function.english.md
understanding-uninitialized-variables.english.md
updating-object-properties.english.md
use-bracket-notation-to-find-the-first-character-in-a-string.english.md
use-bracket-notation-to-find-the-last-character-in-a-string.english.md
use-bracket-notation-to-find-the-nth-character-in-a-string.english.md
use-bracket-notation-to-find-the-nth-to-last-character-in-a-string.english.md
use-conditional-logic-with-if-statements.english.md
use-multiple-conditional-ternary-operators.english.md
use-the-conditional-ternary-operator.english.md
use-the-parseint-function-with-a-radix.english.md
use-the-parseint-function.english.md
using-objects-for-lookups.english.md
word-blanks.english.md
write-reusable-javascript-with-functions.english.md
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
portuguese
russian
spanish
formattingConversion
math-challenges
requiresTests
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-translation.js
package-entry.js
package-lock.json
package.json
utils.js
docs
guide
mock-guide
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.french.md
README.italian.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
* feat(curriculum): Add Basic JS Scrimba links * Fix: Add missing video url. * fix: update videoUrl
5.3 KiB
5.3 KiB
id, title, challengeType, videoUrl
id | title | challengeType | videoUrl |
---|---|---|---|
56533eb9ac21ba0edf2244cb | Manipulating Complex Objects | 1 | https://scrimba.com/c/c9yNMfR |
Description
var ourMusic = [This is an array which contains one object inside. The object has various pieces of metadata about an album. It also has a nested
{
"artist": "Daft Punk",
"title": "Homework",
"release_year": 1997,
"formats": [
"CD",
"Cassette",
"LP"
],
"gold": true
}
];
"formats"
array. If you want to add more album records, you can do this by adding records to the top level array.
Objects hold data in a property, which has a key-value format. In the example above, "artist": "Daft Punk"
is a property that has a key of "artist"
and a value of "Daft Punk"
.
JavaScript Object Notation or JSON
is a related data interchange format used to store data.
{Note
"artist": "Daft Punk",
"title": "Homework",
"release_year": 1997,
"formats": [
"CD",
"Cassette",
"LP"
],
"gold": true
}
You will need to place a comma after every object in the array, unless it is the last object in the array.
Instructions
myMusic
array. Add artist
and title
strings, release_year
number, and a formats
array of strings.
Tests
tests:
- text: <code>myMusic</code> should be an array
testString: assert(Array.isArray(myMusic), '<code>myMusic</code> should be an array');
- text: <code>myMusic</code> should have at least two elements
testString: assert(myMusic.length > 1, '<code>myMusic</code> should have at least two elements');
- text: <code>myMusic[1]</code> should be an object
testString: assert(typeof myMusic[1] === 'object', '<code>myMusic[1]</code> should be an object');
- text: <code>myMusic[1]</code> should have at least 4 properties
testString: assert(Object.keys(myMusic[1]).length > 3, '<code>myMusic[1]</code> should have at least 4 properties');
- text: <code>myMusic[1]</code> should contain an <code>artist</code> property which is a string
testString: assert(myMusic[1].hasOwnProperty('artist') && typeof myMusic[1].artist === 'string', '<code>myMusic[1]</code> should contain an <code>artist</code> property which is a string');
- text: <code>myMusic[1]</code> should contain a <code>title</code> property which is a string
testString: assert(myMusic[1].hasOwnProperty('title') && typeof myMusic[1].title === 'string', '<code>myMusic[1]</code> should contain a <code>title</code> property which is a string');
- text: <code>myMusic[1]</code> should contain a <code>release_year</code> property which is a number
testString: assert(myMusic[1].hasOwnProperty('release_year') && typeof myMusic[1].release_year === 'number', '<code>myMusic[1]</code> should contain a <code>release_year</code> property which is a number');
- text: <code>myMusic[1]</code> should contain a <code>formats</code> property which is an array
testString: assert(myMusic[1].hasOwnProperty('formats') && Array.isArray(myMusic[1].formats), '<code>myMusic[1]</code> should contain a <code>formats</code> property which is an array');
- text: <code>formats</code> should be an array of strings with at least two elements
testString: assert(myMusic[1].formats.every(function(item) { return (typeof item === "string")}) && myMusic[1].formats.length > 1, '<code>formats</code> should be an array of strings with at least two elements');
Challenge Seed
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CD",
"8T",
"LP"
],
"gold": true
}
// Add record here
];
After Test
(function(x){ if (Array.isArray(x)) { return JSON.stringify(x); } return "myMusic is not an array"})(myMusic);
Solution
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
},
{
"artist": "ABBA",
"title": "Ring Ring",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP",
"CD",
]
}
];