Created
December 18, 2018 11:03
-
-
Save saifsultanc/9dba4096d53194aca99c57dfc752a459 to your computer and use it in GitHub Desktop.
JSPlayground created by saifsultanc - https://repl.it/@saifsultanc/JSPlayground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup | |
var collection = { | |
"2548": { | |
"album": "Slippery When Wet", | |
"artist": "Bon Jovi", | |
"tracks": [ | |
"Let It Rock", | |
"You Give Love a Bad Name" | |
] | |
}, | |
"2468": { | |
"album": "1999", | |
"artist": "Prince", | |
"tracks": [ | |
"1999", | |
"Little Red Corvette" | |
] | |
}, | |
"1245": { | |
"artist": "Robert Palmer", | |
"tracks": [ ] | |
}, | |
"5439": { | |
"album": "ABBA Gold" | |
} | |
}; | |
// Keep a copy of the collection for tests | |
var collectionCopy = JSON.parse(JSON.stringify(collection)); | |
// Only change code below this line | |
function updateRecords(id, prop, value) { | |
if (value.length == 0) { | |
delete collection[id][prop]; | |
} | |
else { | |
collection[id][prop] = value; | |
} | |
return collection; | |
} | |
// Alter values below to test your code | |
updateRecords(5439, "artist", "ABBA"); | |
// practice code | |
/*console.log("Hello World"); | |
var number = 5; // in-line comment | |
console.log(++number); | |
number = "five"; | |
console.log(number); | |
var a; | |
console.log(a); | |
a = a + "lol"; | |
console.log(a); | |
var product = 2.01 * 2.5; | |
console.log(product); | |
var str = "Hello"; | |
console.log(str); | |
str[0]='h'; | |
console.log(str); | |
var myArray = [5, 6, 7]; | |
console.log(myArray.pop()); | |
myArray.push(8); | |
console.log(myArray); | |
console.log(myArray.shift()); | |
myArray.unshift(4); | |
console.log(JSON.stringify(myArray)); | |
var a = 3; | |
var b = "3"; | |
if (a=b) | |
console.log("test 1 true"); | |
else | |
console.log("test 1 false"); | |
if (a==b) | |
console.log("test 2 true"); | |
else | |
console.log("test 2 false"); | |
if (a===b) | |
console.log("test 3 true"); | |
else | |
console.log("test 3 false"); | |
var student = { | |
"name" : "John", | |
"marks" : 67 | |
}; | |
student["age"] = 12; | |
delete student["age"]; | |
console.log(student); | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment