Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Created December 18, 2018 11:03
Show Gist options
  • Save saifsultanc/f2df50015f57c9c535265739e6710410 to your computer and use it in GitHub Desktop.
Save saifsultanc/f2df50015f57c9c535265739e6710410 to your computer and use it in GitHub Desktop.
JSPlayground created by saifsultanc - https://repl.it/@saifsultanc/JSPlayground
// 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