From 4f99941ea7b012d4901ea0cb4944a6f0691c0f81 Mon Sep 17 00:00:00 2001 From: johnpaulgarcia Date: Tue, 28 May 2019 14:58:59 +0800 Subject: [PATCH] done --- arrayProperty.js | 9 ++++- instanceArray.js | 14 ++++---- quizApp.js | 60 +++++++++++++++++++++++++--------- sayName.js | 14 ++++++-- test/spec/arrayPropertySpec.js | 8 ----- test/spec/quizAppSpec.js | 8 ----- test/spec/sayNameSpec.js | 8 ----- user.json | 4 +-- 8 files changed, 72 insertions(+), 53 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..79d096a 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -1,5 +1,12 @@ //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. - +String.prototype.reverse = function(){ + let ret = ""; + for(i = this.length - 1;i>-1;i--){ + ret+=this[i]; + } + + return ret; +} //code here \ No newline at end of file diff --git a/instanceArray.js b/instanceArray.js index ab752ac..514734b 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -12,30 +12,30 @@ var User = function(name, email, pw){ } //Create an Array called 'users' that will store all our instances of User. - + let users = []; //code here //Now create and push into your users array 3 separate instances of User using the data from above in that exact order - + users.push(new User('John','john.garcia@boom.camp','i'),new User('Aodhan','aodhan@boom.camp','iLoveJS'),new User('Greg','greg@boom.camp','iLovePython'),new User('Oscar','oscar@boom.camp','iLoveSoccer')); //code here console.log('Aodhan\'s information is '); //Console.log all of Aodhan information - +console.log(users.filter(user => user.name === "Aodhan")); //code here console.log('Oscar\'s information is '); //Now console.log all of Oscars information - +console.log(users.filter(user => user.name === "Oscar")); //code here //Now create another instance of User using your own information and then add that to your users array. - + let user = new User('John','john.garcia@boom.camp','i'); //code here console.log('All my users names are '); //Now loop through your users Array and console.log every users name. - - //code here + users.forEach(name => console.log(name.name)); + //code here \ No newline at end of file diff --git a/quizApp.js b/quizApp.js index 083bd6c..0de345a 100644 --- a/quizApp.js +++ b/quizApp.js @@ -4,28 +4,47 @@ //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 +let QuizUser = function(name,email,password,totalScore) { + return { + name, + email, + password, + totalScore + } +} +//code here //Create a Question constructor that accepts title, answersArray, rightAnswer, and difficulty parameters - - //code here +let Question = function(title,answersArray,rightAnswer,difficulty) { +return { + title, + answersArray, + rightAnswer, + difficulty +} +} +//code here //Create a quizUsers Array which is going to hold all of our users. - - //code here +let quizUsers = []; +//code here //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( + new QuizUser("Jake","jake@boom.camp","j4k3",0), + new QuizUser("Anna","anna@boom.camp","4nn4",0), + new QuizUser("Luke","luke@boom.camp","7uk3",0) +) +//code here //Create a questions Array which is going to hold all of our questions - - //code here +let questions = []; +let answersArray = []; +//code here //Now, let's say we wanted to create a quiz about JavaScript. Create three instances of Question which contain the following data @@ -33,16 +52,25 @@ //title: 'T/F: JavaScript is just a scripting version of Java' //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 + questions.push( + new Question("T/F: Inheritance is achieved in JavaScript through Prototypes?",answersArray,"true",'hard'), + new Question("T/F: JavaScript is just a scripting version of Java",answersArray,"true",'hard'), + new Question("T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value",answersArray,"true",'hard') + ); +//code here //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 ...'); //Now loop console.log your users array and your questions array and verify that they're both holding the right data. - - //code here - +quizUsers.forEach(key => { + console.log(key); +}) + +questions.forEach(key => { + console.log(key); +}) +//code here diff --git a/sayName.js b/sayName.js index 6e28b51..5bf7e6c 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. +let Person = function(name,age){ + this.name = name; + this.age = age; +} //code here //Now create three instances of Person with data you make up - + new Person("Jake",20); + new Person("Luke",30); + new Person("Dan",20); //code here //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); + } + //code here \ No newline at end of file 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'); diff --git a/user.json b/user.json index 4ac80a0..2aaf13a 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "John Paul Garcia", + "email": "john.garcia@boom.camp" }