Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- function makeStudentsReport(data) {
- users.forEach(function(data) {
- return ( data.name + ':' + data.grade)
- };
- };
- /* From here down, you are not expected to
- understand.... for now :)
- Nothing to see here!
- */
- // tests
- function testIt() {
- var testData = [
- {name: 'Jane Doe', grade: 'A'},
- {name: 'John Dough', grade: 'B'},
- {name: 'Jill Do', grade: 'A'}
- ];
- var expectations = [
- 'Jane Doe: A',
- 'John Dough: B',
- 'Jill Do: A'
- ];
- var results = makeStudentsReport(testData);
- if (!(results && results instanceof Array)) {
- console.error(
- 'FAILURE: `makeStudentsReport` must return an array');
- return
- }
- if (results.length !== testData.length) {
- console.error(
- 'FAILURE: test data had length of ' + testData.length +
- ' but `makeStudentsReport` returned array of length ' + results.length);
- return
- }
- for (var i=0; i < expectations.length; i++) {
- var expect = expectations[i];
- if (!results.find(function(item) {
- return item === expect;
- })) {
- console.error(
- 'FAILURE: `makeStudentsReport` is not ' +
- 'producing expected strings'
- );
- return
- }
- }
- console.log('SUCCESS: `makeStudentsReport` is working');
- }
- testIt();
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">function makeStudentsReport(data) {
- users.forEach(function(data) {
- return ( data.name + ':' + data.grade)
- };
- };
- /* From here down, you are not expected to
- understand.... for now :)
- Nothing to see here!
- */
- // tests
- function testIt() {
- var testData = [
- {name: 'Jane Doe', grade: 'A'},
- {name: 'John Dough', grade: 'B'},
- {name: 'Jill Do', grade: 'A'}
- ];
- var expectations = [
- 'Jane Doe: A',
- 'John Dough: B',
- 'Jill Do: A'
- ];
- var results = makeStudentsReport(testData);
- if (!(results && results instanceof Array)) {
- console.error(
- 'FAILURE: `makeStudentsReport` must return an array');
- return
- }
- if (results.length !== testData.length) {
- console.error(
- 'FAILURE: test data had length of ' + testData.length +
- ' but `makeStudentsReport` returned array of length ' + results.length);
- return
- }
- for (var i=0; i < expectations.length; i++) {
- var expect = expectations[i];
- if (!results.find(function(item) {
- return item === expect;
- })) {
- console.error(
- 'FAILURE: `makeStudentsReport` is not ' +
- 'producing expected strings'
- );
- return
- }
- }
- console.log('SUCCESS: `makeStudentsReport` is working');
- }
- testIt();
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement