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
7 changes: 5 additions & 2 deletions arrayProperty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//Note: use var for declaring variables
//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

String.prototype.reverse = function() {
return this.split("").reverse().join("");
}
31 changes: 20 additions & 11 deletions instanceArray.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
//Note: use var for declaring variables
/*
Your 3 Users will be the following.
0) Aodhan, aodhan@boom.camp, 'iLoveJS'
1) Greg, greg@boom.camp, 'iLovePython'
2) Oscar, oscar@boom.camp, 'iLoveSoccer'
*/

var User = function(name, email, pw){
this.name = name;
this.email = email;
this.pw = 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

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
var aodhan = new User('Aodhan', 'aodhan@boom.camp', 'iLoveJS');
var greg = new User('Greg', 'greg@boom.camp', 'iLovePython');
var oscar = new User('Oscar', 'oscar@boom.camp', 'iLoveSoccer');

users.push(aodhan);
users.push(greg);
users.push(oscar);

console.log('Aodhan\'s information is ');
//Console.log all of Aodhan information

//code here
console.log(users.aodhan);

console.log('Oscar\'s information is ');
//Now console.log all of Oscars information

//code here
console.log(users.oscar)


//Now create another instance of User using your own information and then add that to your users array.

//code here
var koji = new User('Koji', 'rolando.adriano@boom.camp', 'iLoveBoomCamp');
users.push(koji);

console.log('All my users names are ');
//Now loop through your users Array and console.log every users name.

//code here
for (var x of users) {
console.log(x)
}
1 change: 1 addition & 0 deletions javascript-4-prototype
Submodule javascript-4-prototype added at e8c19e
42 changes: 33 additions & 9 deletions quizApp.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
//Note: use var for declaring variables
//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.

//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(new QuizUser('one people', 'one@email.com', 'onepassword', 1));
quizUsers.push(new QuizUser('two', 'two@mail.com', 'twopassword', 2));
quizUsers.push(new QuizUser('three people', 'three@mail.com', 'threepassword', 3));



//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
Expand All @@ -34,15 +50,23 @@
//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 firstQuestion = new Question('T/F: Inheritance is achieved in JavaScript through Prototypes?');
var secondQuestion = new Question('T/F: JavaScript is just a scripting version of Java')
var thirdQuestion = 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
questions.push(firstQuestion, secondQuestion, thirdQuestion);

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 (var user_data of quizUsers) {
console.log(user_data);
}

questions.forEach(function(n) {
console.log(n);
})
18 changes: 13 additions & 5 deletions sayName.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
//Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor.
//Note: use var for declaring variables

//code here
//Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor.

function Person(name, age) {
this.name = name;
this.age = age;
}

//Now create three instances of Person with data you make up

//code here
var barbs = new Person('Elijah', '20');
var jaako = new Person('Muhamad Jaako', '35');



//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 log the name of whatever Person instance called it in the console.

//code here
Person.prototype.sayName = function(name) {
console.log(this.name)
}
61 changes: 28 additions & 33 deletions test/spec/arrayPropertySpec.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
const isNode = new Function(`
try {
return this === global;
} catch (e) {
return false;
}
`);

if (isNode()) {
var isNode = ( typeof window === 'undefined' )

if (isNode) {
// test if file is running in a node process
const fs = require('fs');
const path = require('path');

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) {
return /\.js$/.test(path);
} else {
return false;
}
})
.forEach(file => {
global.eval(fs.readFileSync(`${filePath}/${file}`) + '');
});
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) {
return /\.js$/.test(path);
} else {
return false;
}
})
.forEach(file => {
global.eval(fs.readFileSync(`${filePath}/${file}`) + '');
});
}

// Test
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('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');
});
});
});
});
});
});
11 changes: 2 additions & 9 deletions test/spec/instanceArraySpec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
const isNode = new Function(`
try {
return this === global;
} catch (e) {
return false;
}
`);

if (isNode()) {
var isNode = ( typeof window === 'undefined' )
if (isNode) {
// test if file is running in a node process
const fs = require('fs');
const path = require('path');
Expand Down
Loading