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">
- var studentData = [
- {
- name: 'Tim',
- status: 'Current student',
- course: 'Biology'
- },
- {
- name: 'Sue',
- status: 'Withdrawn',
- course: 'Mathematics'
- },
- {
- name: 'Liz',
- status: 'On leave',
- course: 'Computer science'
- }
- ];
- function enrollInSummerSchool(students) {
- // your code here
- var newenroll=[];
- for(i=0;i<students.length;i++){
- var studentsData=students[i];
- var str={name:studentsData.name,
- status:"In Summer school",
- course:studentsData.course}
- newenroll.push(str);
- }
- return newenroll;
- }
- /* From here down, you are not expected to understand.... for now :)
- Nothing to see here!
- */
- // tests
- function testIt() {
- var testData = [
- {
- name: 'Burt',
- status: 'Playing hooky',
- course: 'Biology'
- },
- {
- name: 'Melanie',
- status: 'Sick',
- course: 'Mathematics'
- },
- {
- name: 'Leonard',
- status: 'AWOL',
- course: 'Computer science'
- }
- ];
- var results = enrollInSummerSchool(testData);
- if (!(results && results instanceof Array)) {
- console.error('FAILURE: `enrollSummerSchool` must return an array');
- return
- }
- for (var i=0; i<testData.length; i++) {
- var result = results.find(function(_result) {
- return (
- _result.name === testData[i].name &&
- _result.course === testData[i].course &&
- _result.status === 'In Summer school');
- });
- if (!result) {
- console.error(
- 'FAILURE: `enrollSummerSchool` should return ' +
- 'original key/value pairs for each student, and ' +
- 'update `status` to "In Summer school"');
- return
- }
- }
- console.info('SUCCESS: `enrollSummerSchool` is working');
- }
- testIt();
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">var studentData = [
- {
- name: 'Tim',
- status: 'Current student',
- course: 'Biology'
- },
- {
- name: 'Sue',
- status: 'Withdrawn',
- course: 'Mathematics'
- },
- {
- name: 'Liz',
- status: 'On leave',
- course: 'Computer science'
- }
- ];
- function enrollInSummerSchool(students) {
- // your code here
- var newenroll=[];
- for(i=0;i<students.length;i++){
- var studentsData=students[i];
- var str={name:studentsData.name,
- status:"In Summer school",
- course:studentsData.course}
- newenroll.push(str);
- }
- return newenroll;
- }
- /* From here down, you are not expected to understand.... for now :)
- Nothing to see here!
- */
- // tests
- function testIt() {
- var testData = [
- {
- name: 'Burt',
- status: 'Playing hooky',
- course: 'Biology'
- },
- {
- name: 'Melanie',
- status: 'Sick',
- course: 'Mathematics'
- },
- {
- name: 'Leonard',
- status: 'AWOL',
- course: 'Computer science'
- }
- ];
- var results = enrollInSummerSchool(testData);
- if (!(results && results instanceof Array)) {
- console.error('FAILURE: `enrollSummerSchool` must return an array');
- return
- }
- for (var i=0; i<testData.length; i++) {
- var result = results.find(function(_result) {
- return (
- _result.name === testData[i].name &&
- _result.course === testData[i].course &&
- _result.status === 'In Summer school');
- });
- if (!result) {
- console.error(
- 'FAILURE: `enrollSummerSchool` should return ' +
- 'original key/value pairs for each student, and ' +
- 'update `status` to "In Summer school"');
- return
- }
- }
- console.info('SUCCESS: `enrollSummerSchool` is working');
- }
- testIt();</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement