Skip to content
4 changes: 3 additions & 1 deletion paperproblems/array-functions/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ var dogs = animals.filter(
function(animal)
{return animal.species === 'dog';});

console.log(dogs.length);
console.log(dogs.length);

//2
4 changes: 3 additions & 1 deletion paperproblems/array-functions/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ var letterN = animals.filter(function(animal) {
return animal.name !== undefined && animal.name[0] === 'N'
});

console.log(letterN[0].name);
console.log(letterN[0].name);

//Nacho
4 changes: 3 additions & 1 deletion paperproblems/array-functions/problem3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ var animals = [
var animalNames = animals.map(
function(animal) {return animal.name});

console.log(animalNames.join());
console.log(animalNames.join());

//Nacho,Ramses,Flufftail,Popcorn,Neckbeard,
4 changes: 2 additions & 2 deletions paperproblems/array-functions/problem4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function isDog(animal) {
return animal.species === 'dog';
}

animals.some(isDog)
animals.every(isDog)
animals.some(isDog) //true
animals.every(isDog) //false



14 changes: 7 additions & 7 deletions paperproblems/arrow-functions/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ For each of the following expressions:
- Does it have a syntax error?
- If it doesn't have a syntax error, what are the probable input and output types of the function?

a) x => x + 1
a) x => x + 1 //no syntax error, input type: number, output type: number

b) x, y => x * y
b) x, y => x * y //need () for the arguments, input type: number, output type: number

c) x => { x * 2 }
c) x => { x * 2 } //need no {} OR a return before x*2, input type: number, output type: number

d) (x, z) => {console.log(z); return x * z}
d) (x, z) => {console.log(z); return x * z} //no syntax error, input type: number, output type: number

e) x => console.log(z); return x * z
e) x => console.log(z); return x * z //need {} andz must be defined, input type: number, output type: number

f) (x) => x * 2
f) (x) => x * 2 //ok but you remove () for the parameter, input type: number, output type: number

e) () => console.log("hello")
e) () => console.log("hello") //no syntax error, input type: none, output type: string

When you're done, check all your answers in the developer console.
4 changes: 3 additions & 1 deletion paperproblems/callbacks/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ function h() {
setTimeout(f, 1000);
}

setTimeout(h, 200);
setTimeout(h, 200);

//This programme log "Hello!" after 1700 ms
7 changes: 6 additions & 1 deletion paperproblems/callbacks/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ function h() {
setInterval(g, 1000);
}

setInterval(h, 1000);
setInterval(h, 1000);

//This program calls h() every second
//h() calls g() every second
//g() logs "Hello!"
//There is an "Hello!" more at each call
2 changes: 1 addition & 1 deletion paperproblems/classes/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class Dog {
}
}

var someDog = new Dog("schnitzel", 2, "male");
var someDog = new Dog("schnitzel", 2, "male");
8 changes: 6 additions & 2 deletions paperproblems/classes/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ class Person {
}
toString() {
return "My name is " + this.name +
"and I'm " + this.age + " and I make " + this.salary;
" and I'm " + this.age + " and I make " + this.salary;
}
}

var bob = new Person(25, "Bob", 40000);

bob.increaseSalary(-500);
console.log(bob.toString());
console.log(bob.toString());

//output:
Yay!
My name is Bob and I'm 25 and I make 39500
4 changes: 3 additions & 1 deletion paperproblems/conditional-operator/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ function f(x) {
return x < 5 ? 3 : x > 8 ? 4 : x == 6 ? 12 : 9;
}

console.log(f(5));
console.log(f(5));

//output : 9
4 changes: 3 additions & 1 deletion paperproblems/constructor-functions/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ var bob = new Person("Bob", 30);

Person.prototype.leave = function() {return this.name + " is leaving";}

bob.leave();
bob.leave();

//output "Bob is leaving" because the property leave is correctly added to the prototype of the function Person
4 changes: 3 additions & 1 deletion paperproblems/constructor-functions/problem3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Person.prototype.salary = Person.prototype.salary + 300;
Person.__proto__.salary = Person.__proto__.salary + 400;
bob.salary = bob.salary + 50;

console.log(bob.salary);
console.log(bob.salary);

// output : 40450 because line 16 needs a "prototype" instead of "__proto__"
4 changes: 3 additions & 1 deletion paperproblems/constructor-functions/problem4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ var bob = Person("Bob", 30);

bob.name = bob.name + " Dole";

bob.greet();
bob.greet();

//output: error because the var bob need to use the constructor to define all its properties : var bob = new Person("Bob", 30)
9 changes: 9 additions & 0 deletions paperproblems/constructor-functions/problem5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ function Person(name, age) {
}

var bob = new Person("Bob", 30);


function person(name, age) {
return {fname: name, age: age, greet: function(){console.log("Hello my name is " + name)}}
}

var bob = person('Bob', 30)

var sue = new Person("Sue", 24);

4 changes: 3 additions & 1 deletion paperproblems/inheritance/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class Square extends Shape {
}

var s = new Square(5);
console.log(s.toString());
console.log(s.toString());

//output : square with area 25 and perimeter 20
17 changes: 17 additions & 0 deletions paperproblems/inheritance/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ class Shape {
this.area() + " and perimeter " + this.perimeter();
}
}

class Rectangle extends Shape {
constructor(height, width) {
super("rectangle");
this.height = height;
this.width = width;
}
area() {
return this.height * this.width;
}
perimeter() {
return this.height * 2 + this.width * 2;
}
}

var s = new Rectangle(5,3);
console.log(s.toString());
4 changes: 4 additions & 0 deletions paperproblems/variable-scoping/problem1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ function f() {

f();
f();

//output:
2
4
6 changes: 5 additions & 1 deletion paperproblems/variable-scoping/problem2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ function f() {
}

f();
f();
f();

output:
2
2
8 changes: 7 additions & 1 deletion paperproblems/variable-scoping/problem3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ function f() {

f();
f();
console.log(y);
console.log(y);

//output:

7
9
3
4 changes: 3 additions & 1 deletion paperproblems/variable-scoping/problem4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ function f() {
}

}
}
}

//variables in scope: f, y, g, z, h and p
Loading