From 34d407f2065a76660d694c1c1f93ca0427118aff Mon Sep 17 00:00:00 2001 From: echoaldemo Date: Tue, 28 May 2019 15:13:48 +0800 Subject: [PATCH 1/5] user json added and instanceArray.js completed --- instanceArray.js | 22 +++++++++++++++------- user.json | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/instanceArray.js b/instanceArray.js index ab752ac..73245db 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -13,29 +13,37 @@ var User = function(name, email, pw){ //Create an Array called 'users' that will store all our instances of User. - //code here + let 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 + var user1 = new User('Aodhan', 'aodhan@boom.camp', 'iLoveJS') + user2 = new User('Greg', 'greg@boom.camp', 'iLovePython') + user3 = new User('Oscar', 'oscar@boom.camp', 'iLoveSoccer') + + users.push(user1, user2, user3) + console.log(users) console.log('Aodhan\'s information is '); //Console.log all of Aodhan information - //code here + console.log(user1) console.log('Oscar\'s information is '); //Now console.log all of Oscars information - //code here + console.log(user3) //Now create another instance of User using your own information and then add that to your users array. - //code here + var user4 = new User('Jericho', 'jericho.aldemo@boom.camp', '12345') + users.push(user4) console.log('All my users names are '); //Now loop through your users Array and console.log every users name. - - //code here + users.forEach(function (element) { + console.log(element.name) + }) + diff --git a/user.json b/user.json index 4ac80a0..f978505 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Jericho Aldemo", + "email": "jericho.aldemo@boom.camp" } From 76f47b2d4905a07c7b1d553c7241c34ac815292e Mon Sep 17 00:00:00 2001 From: echoaldemo Date: Tue, 28 May 2019 15:33:52 +0800 Subject: [PATCH 2/5] completed sayName.js --- sayName.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sayName.js b/sayName.js index 6e28b51..0bdae61 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,22 @@ //Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. - //code here + var Person = function(name, age) { + this.name = name + this.age = age + } //Now create three instances of Person with data you make up - //code here + var p1 = new Person('Jericho', 20) + p2 = new Person('Jhoanne', 22) + p3 = new Person('Nico', 24) //Now add a sayName method on your Person class that will alert the name of whatever Person instance called it. - //code here + Person.prototype.sayName = function () { + alert(this.name) + } + + From ebd6d5b0fc0ce62bae7f098fb3038ce140851194 Mon Sep 17 00:00:00 2001 From: echoaldemo Date: Tue, 28 May 2019 16:04:40 +0800 Subject: [PATCH 3/5] edited spec files because of error in test suite --- test/spec/arrayPropertySpec.js | 8 -------- test/spec/quizAppSpec.js | 8 -------- test/spec/sayNameSpec.js | 8 -------- 3 files changed, 24 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'); 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'); 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 95eae39ebe08514fa2a09bf28fb71ef20ae5979c Mon Sep 17 00:00:00 2001 From: echoaldemo Date: Tue, 28 May 2019 16:06:20 +0800 Subject: [PATCH 4/5] completed arrayProperty.js --- arrayProperty.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..7789af1 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -1,5 +1,9 @@ //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 + +String.prototype.reverse = function () { + var splitString = this.split("") + var reverseArray = splitString.reverse() + return reverseArray.join("") +} \ No newline at end of file From 0bffdc2a84486ebaa8245f8b17e36fc8817fd54b Mon Sep 17 00:00:00 2001 From: echoaldemo Date: Tue, 28 May 2019 16:28:29 +0800 Subject: [PATCH 5/5] quizApp.js completed --- quizApp.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/quizApp.js b/quizApp.js index 083bd6c..e13d9fc 100644 --- a/quizApp.js +++ b/quizApp.js @@ -5,27 +5,40 @@ //Create a QuizUser constructor that accepts name, email, password, and totalScore parameters and set them appropriatly - //code here +var QuizUser = function(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 +var Question = function(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 +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 +var per1 = new QuizUser('Jericho Aldemo', 'jericho@boom.camp', 'okay123', 0), + per2 = new QuizUser('Pia Ariate', 'pia@boom.camp', 'pia1234', 0), + per3 = new QuizUser('Paolo Lustria', 'paolo@boom.camp', 'paolo123', 0) +quizUsers.push(per1, per2, per3) //Create a questions Array which is going to hold all of our questions - //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 @@ -34,15 +47,18 @@ //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 +var ques1 = new Question('T/F: Inheritance is achieved in JavaScript through Prototypes?', [true, false, false], true, 'Hard') +var ques2 = new Question('T/F: JavaScript is just a scripting version of Java', [false, true, false], true, 'Medium') +var ques3 = new Question("T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", [true, true, true], true, 'Easy') //Now push all of your instances of Question into the questions Array - //code here +questions.push(ques1, ques2, ques3) 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 +console.log(quizUsers) +console.log(questions)