Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions arrayProperty.js
Original file line number Diff line number Diff line change
@@ -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

//code here
String.prototype.reverse = function() {
return this.split("")
.reverse()
.join("");
};
// console.log("sampl".reverse());
42 changes: 25 additions & 17 deletions instanceArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
81 changes: 57 additions & 24 deletions quizApp.js
Original file line number Diff line number Diff line change
@@ -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]);
}
20 changes: 13 additions & 7 deletions sayName.js
Original file line number Diff line number Diff line change
@@ -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);
};
24 changes: 12 additions & 12 deletions test/spec/arrayPropertySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
});
});
});
Expand Down
78 changes: 39 additions & 39 deletions test/spec/quizAppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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++) {
Expand All @@ -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++) {
Expand Down
Loading