diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..43e5373 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -1,5 +1,11 @@ //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(""); +}; +// console.log("sampl".reverse()); diff --git a/instanceArray.js b/instanceArray.js index ab752ac..2a8ed3e 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -4,38 +4,46 @@ 1) Greg, greg@boom.camp, 'iLovePython' 2) Oscar, oscar@boom.camp, 'iLoveSoccer' */ - -var User = function(name, email, pw){ +var User = function(name, email, pw) { this.name = name; this.email = email; this.pw = pw; -} +}; //Create an Array called 'users' that will store all our instances of User. - //code here - +//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 +//code here +var firstInfo = new User("Aodhan", "aodhan@boom.camp", "iLoveJS"); +users.push(firstInfo); +var secondInfo = new User("Greg", "greg@boom.camp", "iLovePython"); +users.push(secondInfo); +var thirdInfo = new User("Oscar", "oscar@boom.camp", "iLoveSoccer"); +users.push(thirdInfo); -console.log('Aodhan\'s information is '); +console.log("Aodhan's information is "); //Console.log all of Aodhan information - //code here - -console.log('Oscar\'s information is '); +//code here +console.log(firstInfo); +console.log("Oscar's information is "); //Now console.log all of Oscars information - //code here - - +//code here +console.log(thirdInfo); //Now create another instance of User using your own information and then add that to your users array. - //code here - -console.log('All my users names are '); +//code here +var fourthInfo = new User("Rap", "raphael.raquion@boom.camp", "imbatman"); +users.push(fourthInfo); +console.log("All my users names are "); //Now loop through your users Array and console.log every users name. - //code here +//code here +for (let i in users) { + console.log(users[i].name); +} diff --git a/quizApp.js b/quizApp.js index 083bd6c..52e2f9b 100644 --- a/quizApp.js +++ b/quizApp.js @@ -1,48 +1,81 @@ -//We're going to create the JS for a basic quiz application. +//We're going to create the JS for a basic quiz application. //Let's think about the nature of this quiz app first. We're going to be creating lots of user objects, and we're -//also going to be creating lots of Question objects. Those would make two perfectly good constructors. +//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 - - +//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 - - +//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 - - +//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 - - +//code here +var firstInfo = new User("Aodhan", "aodhan@boom.camp", "password1", 95); +quizUsers.push(firstInfo); +var secondInfo = new User("Greg", "greg@boom.camp", "password2", 90); +quizUsers.push(secondInfo); +var thirdInfo = new User("Oscar", "oscar@boom.camp", "password3", 85); +quizUsers.push(thirdInfo); //Create a questions Array which is going to hold all of our questions - //code here - - +//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?' //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 - +//code here +var firstQst = new Question( + "T/F", + "Inheritance is achieved in JavaScript through Prototypes?", + "T", + "Easy" +); +var secondQst = new Question( + "T/F", + "JavaScript is just a scripting version of Java?", + "T", + "Intermediate" +); +var thirdQst = new Question( + "T/F", + "In Javascript, == doesn't check 'type' but just the value - where === checks type and value", + "T", + "Difficult" +); //Now push all of your instances of Question into the questions Array - //code here - -console.log('My users Array and my questions arrray are ...'); +//code here +questions.push(firstQst, secondQst, thirdQst); +console.log(questions); +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 - +//code here +for (x in quizUsers) { + console.log(Object.values(quizUsers[x])); +} +for (y in questions) { + console.log(questions[y]); +} diff --git a/sayName.js b/sayName.js index 6e28b51..775652d 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,19 @@ //Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. - //code here - - +//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 - - +//code here +var personOne = new Person("Aodhan", 28); +var personTwo = new Person("Greg", 28); +var personThree = new Person("Oscar", 28); //Now add a sayName method on your Person class that will alert the name of whatever Person instance called it. - //code here +//code here +Person.prototype.sayName = function() { + alert(this.name); +}; diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index 6907a75..5504f32 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -8,10 +8,10 @@ const isNode = new Function(` if (isNode()) { // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); + const fs = require("fs"); + const path = require("path"); - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + const filePath = path.resolve(__dirname, "../../"); // this should be the root dir fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute .filter(path => { if (path) { @@ -21,22 +21,22 @@ if (isNode()) { } }) .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + global.eval(fs.readFileSync(`${filePath}/${file}`) + ""); }); } // Test -describe('arrayProperty', function() { - describe('String', function() { - it('should have a reverse method', function() { - var str = 'Hello'; +describe("arrayProperty", function() { + describe("String", function() { + it("should have a reverse method", function() { + var str = "Hello"; expect(str.reverse).toBeDefined(); expect(str.reverse).toEqual(jasmine.any(Function)); }); - describe('reverse method', function() { - it('should reverse the string', function() { - var str = 'Hello'; - expect(str.reverse()).toEqual('olleH'); + describe("reverse method", function() { + it("should reverse the string", function() { + var str = "Hello"; + expect(str.reverse()).toEqual("olleH"); }); }); }); diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index 8e0c63c..5e35b94 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -8,10 +8,10 @@ const isNode = new Function(` if (isNode()) { // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); + const fs = require("fs"); + const path = require("path"); - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + const filePath = path.resolve(__dirname, "../../"); // this should be the root dir fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute .filter(path => { if (path) { @@ -21,64 +21,64 @@ if (isNode()) { } }) .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + global.eval(fs.readFileSync(`${filePath}/${file}`) + ""); }); } -describe('quizApp', function() { - describe('QuizUser', function() { - it('should exist', function() { +describe("quizApp", function() { + describe("QuizUser", function() { + it("should exist", function() { expect(QuizUser).toBeDefined(); }); - it('should be a function', function() { + it("should be a function", function() { expect(QuizUser).toEqual(jasmine.any(Function)); }); - it('should return an object when called with new', function() { - var quizUser = new QuizUser('Tester', 'test', 'test', 0); + it("should return an object when called with new", function() { + var quizUser = new QuizUser("Tester", "test", "test", 0); expect(quizUser).toEqual(jasmine.any(Object)); }); - describe('return object', function() { - it('should have name, email, password, and totalScore properties', function() { - var quizUser = new QuizUser('Tester', 'test', 'test', 0); - expect(quizUser.hasOwnProperty('name')).toBe(true); - expect(quizUser.hasOwnProperty('email')).toBe(true); - expect(quizUser.hasOwnProperty('password')).toBe(true); - expect(quizUser.hasOwnProperty('totalScore')).toBe(true); + describe("return object", function() { + it("should have name, email, password, and totalScore properties", function() { + var quizUser = new QuizUser("Tester", "test", "test", 0); + expect(quizUser.hasOwnProperty("name")).toBe(true); + expect(quizUser.hasOwnProperty("email")).toBe(true); + expect(quizUser.hasOwnProperty("password")).toBe(true); + expect(quizUser.hasOwnProperty("totalScore")).toBe(true); }); }); }); - describe('Question', function() { - it('should exist', function() { + describe("Question", function() { + it("should exist", function() { expect(Question).toBeDefined(); }); - it('should be a function', function() { + it("should be a function", function() { expect(Question).toEqual(jasmine.any(Function)); }); - it('should return an object when called with new', function() { - var question = new Question('Tester', 'test', 'test', 0); + it("should return an object when called with new", function() { + var question = new Question("Tester", "test", "test", 0); expect(question).toEqual(jasmine.any(Object)); }); - describe('return object', function() { - it('should have title, answersArray, rightAnswer, and difficulty properties', function() { - var question = new Question('Tester', 'test', 'test', 0); - expect(question.hasOwnProperty('title')).toBe(true); - expect(question.hasOwnProperty('answersArray')).toBe(true); - expect(question.hasOwnProperty('rightAnswer')).toBe(true); - expect(question.hasOwnProperty('difficulty')).toBe(true); + describe("return object", function() { + it("should have title, answersArray, rightAnswer, and difficulty properties", function() { + var question = new Question("Tester", "test", "test", 0); + expect(question.hasOwnProperty("title")).toBe(true); + expect(question.hasOwnProperty("answersArray")).toBe(true); + expect(question.hasOwnProperty("rightAnswer")).toBe(true); + expect(question.hasOwnProperty("difficulty")).toBe(true); }); }); }); - describe('quizUsers', function() { - it('should exist', function() { + describe("quizUsers", function() { + it("should exist", function() { expect(quizUsers).toBeDefined(); }); - it('should be an array', function() { + it("should be an array", function() { expect(quizUsers).toEqual(jasmine.any(Array)); }); - it('should have three items', function() { + it("should have three items", function() { expect(quizUsers.length).toBe(3); }); - it('(when complete) should only contain instances of QuizUser', function() { + it("(when complete) should only contain instances of QuizUser", function() { var areAllUsers = true; var quizUsers = quizUsers || []; for (var i = 0; i < quizUsers.length; i++) { @@ -89,17 +89,17 @@ describe('quizApp', function() { expect(areAllUsers).toBe(true); }); }); - describe('questions', function() { - it('should exist', function() { + describe("questions", function() { + it("should exist", function() { expect(questions).toBeDefined(); }); - it('should be an array', function() { + it("should be an array", function() { expect(questions).toEqual(jasmine.any(Array)); }); - it('should have three items', function() { + it("should have three items", function() { expect(questions.length).toBe(3); }); - it('(when complete) should only contain instances of Question', function() { + it("(when complete) should only contain instances of Question", function() { var areAllQuestions = true; var questions = questions || []; for (var i = 0; i < questions.length; i++) { diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 7fbb7bb..a49023e 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -8,10 +8,10 @@ const isNode = new Function(` if (isNode()) { // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); + const fs = require("fs"); + const path = require("path"); - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + const filePath = path.resolve(__dirname, "../../"); // this should be the root dir fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute .filter(path => { if (path) { @@ -21,43 +21,43 @@ if (isNode()) { } }) .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + global.eval(fs.readFileSync(`${filePath}/${file}`) + ""); }); } -describe('sayName', function() { - describe('Person', function() { - it('should exist', function() { +describe("sayName", function() { + describe("Person", function() { + it("should exist", function() { expect(Person).toBeDefined(); }); - it('should be a function', function() { + it("should be a function", function() { expect(Person).toEqual(jasmine.any(Function)); }); - it('should return an object with name and age properties when invoked with new (e.g. var person = new Person(...))', function() { - var person = new Person('Tester', 25); - expect(person.hasOwnProperty('name')).toBe(true); - expect(person.hasOwnProperty('age')).toBe(true); + it("should return an object with name and age properties when invoked with new (e.g. var person = new Person(...))", function() { + var person = new Person("Tester", 25); + expect(person.hasOwnProperty("name")).toBe(true); + expect(person.hasOwnProperty("age")).toBe(true); }); - describe('return object', function() { - it('should be an instance of Person', function() { - var person = new Person('Tester', 25); + describe("return object", function() { + it("should be an instance of Person", function() { + var person = new Person("Tester", 25); var isPerson = person instanceof Person; expect(isPerson).toBe(true); }); - it('should have access to a sayName method', function() { - var person = new Person('Tester', 25); + it("should have access to a sayName method", function() { + var person = new Person("Tester", 25); expect(person.sayName).toBeDefined(); expect(person.sayName).toEqual(jasmine.any(Function)); }); - describe('sayName', function() { - it('should alert the name of the person on which sayName is invoked', function() { - var tester = new Person('Tester', 25); - var someoneElse = new Person('Simone Elsa', 22); - var alert = spyOn(window, 'alert'); + describe("sayName", function() { + it("should alert the name of the person on which sayName is invoked", function() { + var tester = new Person("Tester", 25); + var someoneElse = new Person("Simone Elsa", 22); + var alert = spyOn(window, "alert"); tester.sayName(); - expect(alert).toHaveBeenCalledWith('Tester'); + expect(alert).toHaveBeenCalledWith("Tester"); someoneElse.sayName(); - expect(alert).toHaveBeenCalledWith('Simone Elsa'); + expect(alert).toHaveBeenCalledWith("Simone Elsa"); }); }); }); diff --git a/user.json b/user.json index 4ac80a0..f01ef9d 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Raphael Raquion", + "email": "raphael.raquion@boom.camp" }