From b64bf2f9ff87262bf95d5b6728e00fee5fd24e8a Mon Sep 17 00:00:00 2001 From: Franco Date: Wed, 16 Oct 2019 05:11:39 -0400 Subject: [PATCH 1/3] practice-prototype --- arrayProperty.js | 5 ++++- instanceArray.js | 21 +++++++++++++-------- quizApp.js | 26 ++++++++++++++++++++------ sayName.js | 12 ++++++++++-- user.json | 4 ++-- 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..993e769 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -2,4 +2,7 @@ //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(){ + return this.split('').reverse().join(''); +} \ No newline at end of file diff --git a/instanceArray.js b/instanceArray.js index ab752ac..a8ed981 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -14,28 +14,33 @@ var User = function(name, email, pw){ //Create an Array called 'users' that will store all our instances of User. //code here - - + var users = []; + const aodhan = new User("Aodhan", "aodhan@boom.camp", 'iLoveJS') + const greg = new User("Greg", "greg@boom.camp", 'iLovePython') + const oscar = new User("Oscar", "oscar@boom.camp", 'iLoveSoccer') //Now create and push into your users array 3 separate instances of User using the data from above in that exact order //code here - -console.log('Aodhan\'s information is '); + var users = [aodhan, greg, oscar]; + console.log(`Aodhan\'s information is ${users[0].name}, ${users[0].email}, ${users[0].pw}`); //Console.log all of Aodhan information //code here - -console.log('Oscar\'s information is '); + + console.log(`Oscar\'s information is ${users[2].name}, ${users[2].name}, ${users[2].name}`); //Now console.log all of Oscars information //code here - + //Now create another instance of User using your own information and then add that to your users array. //code here - + users.push(franco = new User("Franco", "franco@boom.camp", 'iloveJStoo')); console.log('All my users names are '); //Now loop through your users Array and console.log every users name. //code here + for(i in users){ + console.log(users[i].name); + } \ No newline at end of file diff --git a/quizApp.js b/quizApp.js index 083bd6c..0ce45c2 100644 --- a/quizApp.js +++ b/quizApp.js @@ -6,27 +6,39 @@ //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 - +quizUsers.push(user1 = new QuizUser("franco", "franco@boom.camp", "12345", 100)); +quizUsers.push(user2 = new QuizUser("jake", "jake@boom.camp", "asdfg", 100)); +quizUsers.push(user3 = new QuizUser("jeff", "jeff@boom.camp", "qwert", 100)); //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 //title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?' @@ -35,7 +47,9 @@ //Fill in the rest of the required data as you see appropriate. //code here - +questions.push(q1 = new Question("T/F: Inheritance is achieved in JavaScript through Prototypes?", "True or False", "True", "hard")); +questions.push(q2 = new Question("T/F: JavaScript is just a scripting version of Java", "True or False", "False", "easy")); +questions.push(q2 = new Question("T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", "True or False", "True", "easy")); //Now push all of your instances of Question into the questions Array diff --git a/sayName.js b/sayName.js index 6e28b51..71d6c65 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 - +var Person = function(name, age){ + this.name = name; + this.age = age; +} //Now create three instances of Person with data you make up //code here - +p1 = new Person("franco", 21); +p2 = new Person("Jake", 20); +p3 = new Person("Jeff", 21); //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); +} \ No newline at end of file diff --git a/user.json b/user.json index 4ac80a0..987ce8f 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Francisco R. Ifurung", + "email": "francisco.ifurung@boom.camp" } From b90e56dd40e4b02dd9d6056ea281d716fe36c8b3 Mon Sep 17 00:00:00 2001 From: Franco Date: Wed, 16 Oct 2019 23:29:54 -0400 Subject: [PATCH 2/3] test --- test/spec/arrayPropertySpec.js | 7 ------- test/spec/quizAppSpec.js | 7 ------- test/spec/sayNameSpec.js | 7 ------- user.json | 2 +- 4 files changed, 1 insertion(+), 22 deletions(-) diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index 6907a75..b68215d 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,10 +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 diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index 8e0c63c..ecb9af5 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,10 +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 diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 7fbb7bb..8b76117 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,10 +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 diff --git a/user.json b/user.json index 987ce8f..e91bb9f 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { "name": "Francisco R. Ifurung", - "email": "francisco.ifurung@boom.camp" + "email": "francisco.ifurung@boom.camp " } From b9cd17c4cc4acb6e9c1a3250311194e81f43dae7 Mon Sep 17 00:00:00 2001 From: Franco Date: Thu, 17 Oct 2019 03:01:11 -0400 Subject: [PATCH 3/3] second-change spec_runner --- test/spec/arrayPropertySpec.js | 7 +++++++ test/spec/quizAppSpec.js | 7 +++++++ test/spec/sayNameSpec.js | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index b68215d..6907a75 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index ecb9af5..8e0c63c 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 8b76117..7fbb7bb 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process