Guest User

Untitled

a guest
Feb 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function addToList(list, item) {
  12. list.push(item);
  13. return list;
  14. }
  15.  
  16.  
  17.  
  18.  
  19. /* From here down, you are not expected to
  20. understand.... for now :)
  21.  
  22.  
  23. Nothing to see here!
  24.  
  25. */
  26.  
  27.  
  28. // tests
  29.  
  30. function testAddToList() {
  31.  
  32. var input1 = ["red", "blue", "green"]
  33. var input2 = "pink"
  34. var expected = ["red", "blue", "green", "pink"]
  35. var result = addToList(input1, input2);
  36.  
  37. if (
  38. result && result.length && expected.length === result.length &&
  39. expected.every(function(item) {
  40. return result.indexOf(item) > -1;
  41. })) {
  42. console.log('SUCCESS: `addToList` works!');
  43. } else {
  44. console.error('FAILURE: `addToList` is not working');
  45. }
  46. }
  47.  
  48. testAddToList();
  49. </script>
  50.  
  51.  
  52.  
  53. <script id="jsbin-source-javascript" type="text/javascript">function addToList(list, item) {
  54. list.push(item);
  55. return list;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. /* From here down, you are not expected to
  62. understand.... for now :)
  63.  
  64.  
  65. Nothing to see here!
  66.  
  67. */
  68.  
  69.  
  70. // tests
  71.  
  72. function testAddToList() {
  73.  
  74. var input1 = ["red", "blue", "green"]
  75. var input2 = "pink"
  76. var expected = ["red", "blue", "green", "pink"]
  77. var result = addToList(input1, input2);
  78.  
  79. if (
  80. result && result.length && expected.length === result.length &&
  81. expected.every(function(item) {
  82. return result.indexOf(item) > -1;
  83. })) {
  84. console.log('SUCCESS: `addToList` works!');
  85. } else {
  86. console.error('FAILURE: `addToList` is not working');
  87. }
  88. }
  89.  
  90. testAddToList();
  91. </script></body>
  92. </html>
Add Comment
Please, Sign In to add comment