From 39c3b003d709e5e876ae12ec9747cd2fd5998015 Mon Sep 17 00:00:00 2001 From: armanbayona Date: Tue, 28 May 2019 18:14:30 +0800 Subject: [PATCH] final --- arrayProperty.js | 7 ++++++- instanceArray.js | 23 +++++++++++++++++++---- quizApp.js | 37 ++++++++++++++++++++++++++++++++++--- sayName.js | 12 ++++++++++++ user.json | 4 ++-- 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..e5ba5da 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -2,4 +2,9 @@ //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(char) { + var splitString = this.split(""); + var reverseArray = splitString.reverse(); + return reverseArray.join(""); + } diff --git a/instanceArray.js b/instanceArray.js index ab752ac..92599da 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -14,28 +14,43 @@ var User = function(name, email, pw){ //Create an Array called 'users' that will store all our instances of User. //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 + users.push(new User('Aodhan','aodhan@boom.camp','iLoveJS')); + users.push(new User('Greg','greg@boom.camp','iLovePython')); + users.push(new User('Oscar','oscar@boom.camp','iLoveSoccer')); console.log('Aodhan\'s information is '); //Console.log all of Aodhan information - //code here - +//code here +for(property of users) { + if(property.name === 'Aodhan') { + console.log(property); + } +} console.log('Oscar\'s information is '); //Now console.log all of Oscars information //code here - + for(property of users) { + if(property.name === 'Oscar') { + console.log(property); + } + } //Now create another instance of User using your own information and then add that to your users array. //code here + users.push(new User('Arman', 'arman.bayona@boom.camp', 'materialdesign')); console.log('All my users names are '); //Now loop through your users Array and console.log every users name. //code here + for(property of users) { + console.log(property.name); + } \ No newline at end of file diff --git a/quizApp.js b/quizApp.js index 083bd6c..3a60913 100644 --- a/quizApp.js +++ b/quizApp.js @@ -6,26 +6,39 @@ //Create a QuizUser constructor that accepts name, email, password, and totalScore parameters and set them appropriatly //code here - + function QuizUser(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 - + function Question(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("Arman", "Emelyn" , "Sheriline") //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 @@ -35,14 +48,32 @@ //Fill in the rest of the required data as you see appropriate. //code here +var a = new Question('T/F: Inheritance is achieved in JavaScript through Prototypes?'); +var b = new Question('T/F: JavaScript is just a scripting version of Java'); +var c = new Question("T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value"); //Now push all of your instances of Question into the questions Array - //code here +//code here + +questions.push(a); +questions.push(b); +questions.push(c); + 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 + for(property of questions){ + console.log(property); + } + for(property of quizUsers){ + console.log(property); + } + + + + diff --git a/sayName.js b/sayName.js index 6e28b51..9d4e9b1 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,25 @@ //Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. //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 + var arman = new Person('Arman', 20); + var ems = new Person('Emelyn', 20); + var she = new Person('Sheriline', 20); //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); + //console.log(this.name); + } + diff --git a/user.json b/user.json index 4ac80a0..3045978 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Arman Jay M. Bayona", + "email": "arman.bayona@boom.camp" }