From 7305619eea2f1211305903cf9ac03793b3e8504c Mon Sep 17 00:00:00 2001 From: noephilip-restum Date: Wed, 16 Oct 2019 16:48:03 +0800 Subject: [PATCH 1/7] This is a commit message --- SpecRunner.html | 46 ++++++++++++++------------- arrayProperty.js | 14 +++++++-- instanceArray.js | 34 ++++++++++++-------- quizApp.js | 82 +++++++++++++++++++++++++++++++++++++----------- sayName.js | 18 ++++++++--- user.json | 4 +-- 6 files changed, 136 insertions(+), 62 deletions(-) diff --git a/SpecRunner.html b/SpecRunner.html index f19b0e9..ee2d0ad 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -1,30 +1,32 @@ - - - Jasmine Spec Runner v3.4.0 + + + Jasmine Spec Runner v3.4.0 - - + + - - - + + + - - - - - + + + + + - - - - - + + + + + + - - - - + diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..b00b328 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -1,5 +1,15 @@ //Just like you can add methods to your own constructor, you can also add methods and properties to built in classes in JavaScript like Arrays and Objects. //Add a reverse method to the String 'class' so that every instance of String can call reverse and reverse itself. - - //code here \ No newline at end of file + +//code here +String.prototype.reverse = function(str) { + str = this; + return str + .split("") + .reverse() + .join(""); +}; + +var str = "Kobe"; +console.log(str.reverse()); diff --git a/instanceArray.js b/instanceArray.js index ab752ac..ac3588f 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -5,37 +5,45 @@ 2) Oscar, oscar@boom.camp, 'iLoveSoccer' */ -var User = function(name, email, pw){ +var User = function(name, email, pw) { this.name = name; this.email = email; this.pw = pw; -} +}; //Create an Array called 'users' that will store all our instances of User. - //code here - +//code here +var users = []; //Now create and push into your users array 3 separate instances of User using the data from above in that exact order - //code here +//code here +users[0] = new User("Aodhan", "aodhan@boom.camp", "iLoveJS"); +users[1] = new User("Greg", "greg@boom.camp", "iLovePython"); +users[2] = new User("Oscar", "oscar@boom.camp", "iLoveSoccer"); -console.log('Aodhan\'s information is '); +console.log("Aodhan's information is "); //Console.log all of Aodhan information - //code here +//code here +console.log(users[0].name + " " + users[0].email + " " + users[0].pw); -console.log('Oscar\'s information is '); +console.log("Oscar's information is "); //Now console.log all of Oscars information - //code here - +//code here +console.log(users[2].name + " " + users[2].email + " " + users[2].pw); //Now create another instance of User using your own information and then add that to your users array. - //code here +//code here +users[3] = new User("Noe", "noe.restum@boom.camp", "iLoveOof"); -console.log('All my users names are '); +console.log("All my users names are "); //Now loop through your users Array and console.log every users name. - //code here +//code here +for (i in users) { + console.log(users[i].name); +} diff --git a/quizApp.js b/quizApp.js index 083bd6c..79dd7b5 100644 --- a/quizApp.js +++ b/quizApp.js @@ -1,32 +1,48 @@ -//We're going to create the JS for a basic quiz application. +//We're going to create the JS for a basic quiz application. //Let's think about the nature of this quiz app first. We're going to be creating lots of user objects, and we're -//also going to be creating lots of Question objects. Those would make two perfectly good constructors. +//also going to be creating lots of Question objects. Those would make two perfectly good constructors. //Create a QuizUser constructor that accepts name, email, password, and totalScore parameters and set them appropriatly - //code here - +//code here +class QuizUser { + constructor(name, email, password, totalScore) { + this.name = name; + this.email = email; + this.password = password; + this.totalScore = totalScore; + } +} //Create a Question constructor that accepts title, answersArray, rightAnswer, and difficulty parameters - //code here - +//code here +class Question { + constructor(title, answersArray, rightAnswer, difficulty) { + this.title = title; + this.answersArray = answersArray; + this.rightAnswer = rightAnswer; + this.difficulty = difficulty; + } +} //Create a quizUsers Array which is going to hold all of our users. - //code here - +//code here +var quizUsers = []; //Let's say three people signed up for our service, create 3 instances of User and add each to the users Array - //code here - +//code here +quizUsers[0] = new QuizUser("Aodhan", "aodhan@boom.camp", "23_23", "100"); +quizUsers[1] = new QuizUser("Oscar", "oscar@boom.camp", "23_24", "99"); +quizUsers[2] = new QuizUser("Noe", "noe.restum@boom.camp", "23_23", "89"); //Create a questions Array which is going to hold all of our questions - //code here - +//code here +var questions = []; //Now, let's say we wanted to create a quiz about JavaScript. Create three instances of Question which contain the following data //title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?' @@ -34,15 +50,45 @@ //title: "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value" //Fill in the rest of the required data as you see appropriate. - //code here - +//code here +questions.push( + new Question( + "T/F: Inheritance is achieved in JavaScript through Prototypes?", + ["T", "F"], + "F", + 1 + ) +); +questions.push( + new Question( + "T/F: JavaScript is just a scripting version of Java", + ["T", "F"], + "F", + 1 + ) +); +questions.push( + new Question( + "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", + ["T", "F"], + "T", + 1 + ) +); //Now push all of your instances of Question into the questions Array - //code here +//code here -console.log('My users Array and my questions arrray are ...'); +console.log("My users Array and my questions arrray are ..."); //Now loop console.log your users array and your questions array and verify that they're both holding the right data. - //code here - +//code here +for (i in quizUsers) { + console.log( + quizUsers[i].name, + quizUsers[i].email, + quizUsers[i].password, + quizUsers[i].totalScore + ); +} diff --git a/sayName.js b/sayName.js index 6e28b51..14fc9a0 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,21 @@ //Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. - //code here - +//code here +function Person(name, age) { + this.name = name; + this.age = age; +} //Now create three instances of Person with data you make up - //code here - +//code here +const instructor = new Person("Aodhan", 28); +const instructor1 = new Person("Oscar", 24); +const instructor2 = new Person("Noe", 20); //Now add a sayName method on your Person class that will alert the name of whatever Person instance called it. - //code here +//code here +Person.prototype.sayName = function() { + alert(this.name); +}; diff --git a/user.json b/user.json index 4ac80a0..0e73249 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Noe Philip Gabriel M. Restum", + "email": "noe.restum@boom.camp" } From 30c91c413524b3146353117931331d243c2120ae Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:37:19 +0800 Subject: [PATCH 2/7] Update arrayPropertySpec.js --- test/spec/arrayPropertySpec.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index 6907a75..57b7c39 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,11 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - if (isNode()) { // test if file is running in a node process const fs = require('fs'); From a732d47316af5b4d98f8b71fc27ba45c08eb39ad Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:38:15 +0800 Subject: [PATCH 3/7] Update quizAppSpec.js --- test/spec/quizAppSpec.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index 8e0c63c..625ca0e 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,11 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - if (isNode()) { // test if file is running in a node process const fs = require('fs'); From fab6681e8ceaa34e53d379cfc48c1b0cedef26b4 Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:38:45 +0800 Subject: [PATCH 4/7] Update sayNameSpec.js --- test/spec/sayNameSpec.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 7fbb7bb..d6541a4 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,11 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - if (isNode()) { // test if file is running in a node process const fs = require('fs'); From d1ec5becaee6b72ef2b6f9e88c2d4048252542a2 Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:54:30 +0800 Subject: [PATCH 5/7] Update arrayPropertySpec.js --- test/spec/arrayPropertySpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index 57b7c39..6907a75 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,3 +1,11 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + if (isNode()) { // test if file is running in a node process const fs = require('fs'); From 46154466e4be1bdc18fe3bb5a1bb9e62af25056b Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:54:50 +0800 Subject: [PATCH 6/7] Update quizAppSpec.js --- test/spec/quizAppSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index 625ca0e..8e0c63c 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,3 +1,11 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + if (isNode()) { // test if file is running in a node process const fs = require('fs'); From 265b6b8c4ab3584d9d2cd1080f0ea629a95d25ba Mon Sep 17 00:00:00 2001 From: noephilip-restum <55864659+noephilip-restum@users.noreply.github.com> Date: Thu, 17 Oct 2019 15:55:09 +0800 Subject: [PATCH 7/7] Update sayNameSpec.js --- test/spec/sayNameSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index d6541a4..7fbb7bb 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,3 +1,11 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + if (isNode()) { // test if file is running in a node process const fs = require('fs');