Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 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 makeStudentsReport(data) {
  12. users.forEach(function(data) {
  13. return ( data.name + ':' + data.grade)
  14. };
  15. };
  16.  
  17.  
  18. /* From here down, you are not expected to
  19. understand.... for now :)
  20.  
  21. Nothing to see here!
  22.  
  23. */
  24.  
  25.  
  26. // tests
  27.  
  28. function testIt() {
  29.  
  30. var testData = [
  31. {name: 'Jane Doe', grade: 'A'},
  32. {name: 'John Dough', grade: 'B'},
  33. {name: 'Jill Do', grade: 'A'}
  34. ];
  35.  
  36. var expectations = [
  37. 'Jane Doe: A',
  38. 'John Dough: B',
  39. 'Jill Do: A'
  40. ];
  41.  
  42. var results = makeStudentsReport(testData);
  43.  
  44. if (!(results && results instanceof Array)) {
  45. console.error(
  46. 'FAILURE: `makeStudentsReport` must return an array');
  47. return
  48. }
  49. if (results.length !== testData.length) {
  50. console.error(
  51. 'FAILURE: test data had length of ' + testData.length +
  52. ' but `makeStudentsReport` returned array of length ' + results.length);
  53. return
  54. }
  55. for (var i=0; i < expectations.length; i++) {
  56. var expect = expectations[i];
  57. if (!results.find(function(item) {
  58. return item === expect;
  59. })) {
  60. console.error(
  61. 'FAILURE: `makeStudentsReport` is not ' +
  62. 'producing expected strings'
  63. );
  64. return
  65. }
  66. }
  67. console.log('SUCCESS: `makeStudentsReport` is working');
  68. }
  69.  
  70. testIt();
  71. </script>
  72.  
  73.  
  74.  
  75. <script id="jsbin-source-javascript" type="text/javascript">function makeStudentsReport(data) {
  76. users.forEach(function(data) {
  77. return ( data.name + ':' + data.grade)
  78. };
  79. };
  80.  
  81.  
  82. /* From here down, you are not expected to
  83. understand.... for now :)
  84.  
  85. Nothing to see here!
  86.  
  87. */
  88.  
  89.  
  90. // tests
  91.  
  92. function testIt() {
  93.  
  94. var testData = [
  95. {name: 'Jane Doe', grade: 'A'},
  96. {name: 'John Dough', grade: 'B'},
  97. {name: 'Jill Do', grade: 'A'}
  98. ];
  99.  
  100. var expectations = [
  101. 'Jane Doe: A',
  102. 'John Dough: B',
  103. 'Jill Do: A'
  104. ];
  105.  
  106. var results = makeStudentsReport(testData);
  107.  
  108. if (!(results && results instanceof Array)) {
  109. console.error(
  110. 'FAILURE: `makeStudentsReport` must return an array');
  111. return
  112. }
  113. if (results.length !== testData.length) {
  114. console.error(
  115. 'FAILURE: test data had length of ' + testData.length +
  116. ' but `makeStudentsReport` returned array of length ' + results.length);
  117. return
  118. }
  119. for (var i=0; i < expectations.length; i++) {
  120. var expect = expectations[i];
  121. if (!results.find(function(item) {
  122. return item === expect;
  123. })) {
  124. console.error(
  125. 'FAILURE: `makeStudentsReport` is not ' +
  126. 'producing expected strings'
  127. );
  128. return
  129. }
  130. }
  131. console.log('SUCCESS: `makeStudentsReport` is working');
  132. }
  133.  
  134. testIt();
  135. </script></body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement