Guest User

Untitled

a guest
Dec 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // Setup
  2. var collection = {
  3. "2548": {
  4. "album": "Slippery When Wet",
  5. "artist": "Bon Jovi",
  6. "tracks": [
  7. "Let It Rock",
  8. "You Give Love a Bad Name"
  9. ]
  10. },
  11. "2468": {
  12. "album": "1999",
  13. "artist": "Prince",
  14. "tracks": [
  15. "1999",
  16. "Little Red Corvette"
  17. ]
  18. },
  19. "1245": {
  20. "artist": "Robert Palmer",
  21. "tracks": [ ]
  22. },
  23. "5439": {
  24. "album": "ABBA Gold"
  25. }
  26. };
  27. // Keep a copy of the collection for tests
  28. var collectionCopy = JSON.parse(JSON.stringify(collection));
  29.  
  30. // Only change code below this line
  31. function updateRecords(id, prop, value) {
  32.  
  33. if (value.length == 0) {
  34. delete collection[id][prop];
  35. }
  36. else {
  37. collection[id][prop] = value;
  38. }
  39. return collection;
  40. }
  41.  
  42. // Alter values below to test your code
  43. updateRecords(5439, "artist", "ABBA");
  44.  
  45.  
  46. // practice code
  47. /*console.log("Hello World");
  48. var number = 5; // in-line comment
  49. console.log(++number);
  50. number = "five";
  51. console.log(number);
  52. var a;
  53. console.log(a);
  54. a = a + "lol";
  55. console.log(a);
  56.  
  57. var product = 2.01 * 2.5;
  58. console.log(product);
  59.  
  60. var str = "Hello";
  61. console.log(str);
  62. str[0]='h';
  63. console.log(str);
  64.  
  65. var myArray = [5, 6, 7];
  66. console.log(myArray.pop());
  67. myArray.push(8);
  68. console.log(myArray);
  69. console.log(myArray.shift());
  70. myArray.unshift(4);
  71. console.log(JSON.stringify(myArray));
  72.  
  73.  
  74. var a = 3;
  75. var b = "3";
  76. if (a=b)
  77. console.log("test 1 true");
  78. else
  79. console.log("test 1 false");
  80.  
  81. if (a==b)
  82. console.log("test 2 true");
  83. else
  84. console.log("test 2 false");
  85.  
  86. if (a===b)
  87. console.log("test 3 true");
  88. else
  89. console.log("test 3 false");
  90.  
  91.  
  92. var student = {
  93. "name" : "John",
  94. "marks" : 67
  95. };
  96. student["age"] = 12;
  97. delete student["age"];
  98. console.log(student);
  99. */
Add Comment
Please, Sign In to add comment