diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..a11a2a7 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. +//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() { + return this.split("").reverse().join(""); +} \ No newline at end of file diff --git a/instanceArray.js b/instanceArray.js index ab752ac..6ae608c 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -14,28 +14,40 @@ 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 +//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 +console.log(users[0].name); +console.log(users[0].email); +console.log(users[0].pw); console.log('Oscar\'s information is '); //Now console.log all of Oscars information //code here - +console.log(users[1].name); +console.log(users[1].email); +console.log(users[1].pw); //Now create another instance of User using your own information and then add that to your users array. //code here - +users.push(new User('Jaako','jaako.andes@boom.camp','r3s3rv01rD0gZ')); console.log('All my users names are '); //Now loop through your users Array and console.log every users name. //code here +for(let x of users) { + console.log(x.name); +} \ No newline at end of file diff --git a/quizApp.js b/quizApp.js index 083bd6c..ed860a1 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 - +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 - +let 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(new QuizUser('Jaako','jaako.andes@boom.camp','ioja;diaw','0')); +quizUsers.push(new QuizUser('Koji XiangHung','koji.adriano@boom.camp','ieatdogz4breakfast','0')); +quizUsers.push(new QuizUser('Elijah Papoulouni','elijah.barba@boom.camp','greekshark444','0')); //Create a questions Array which is going to hold all of our questions //code here - +let 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,14 +47,25 @@ //Fill in the rest of the required data as you see appropriate. //code here - +let q1 = new Question('T/F: Inheritance is achieved in JavaScript through Prototypes?','','false','easy'); +let q2 = new Question('T/F: JavaScript is just a scripting version of Java','','false','easy'); +let q3 = new Question("T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value",'','true','easy'); //Now push all of your instances of Question into the questions Array //code here - +questions.push(q1); +questions.push(q2); +questions.push(q3); 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(let wow of quizUsers) { + console.log(wow); +} + +for(let nice of questions) { + console.log(nice); +} \ No newline at end of file diff --git a/sayName.js b/sayName.js index 6e28b51..d1535ed 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,23 @@ -//Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. +//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 jaako = new Person('Jaako', '20'); +var aladeen = new Person('aladeen', '35'); +var zohan = new Person('Zohan', '30'); - -//Now add a sayName method on your Person class that will alert the name of whatever Person instance called it. +//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); +} 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..c25af04 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,10 +1,4 @@ -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..d3e211f 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,10 +1,4 @@ -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 4ac80a0..77ca022 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Jaako Andes", + "email": "jaako.andes@boom.camp" }