Skip to content
Permalink
Browse files
Done all to 5
  • Loading branch information
deoliveg committed Oct 14, 2019
1 parent 3980c45 commit bc77be45c3e1dacb6a8aeeb8c666d59cf67434e9
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 27 deletions.
@@ -34,6 +34,17 @@ try {
*/
function validateEmail(email) {
console.log(email)

var emailLenght = email.length
if (emailLenght <= 5){ throw new TypeError("That email is too short to be a real email")}

var atSymbol = email.indexOf('@')
if (atSymbol == 0) { throw new TypeError("At symbols in the beginning")}
if (email.includes('@') == false) { throw new TypeError("no At symbols")}

var periodSymbol = email.indexOf('.')
if ((atSymbol+1 < periodSymbol) == false || (periodSymbol < emailLenght - 1) == false) { throw new TypeError("period is on the wrong place in the email")}

return true
}

@@ -6,6 +6,8 @@
const employee = {
firstName: 'Colin',
'last name': 'Stephen',
gender: 'Male',
dateOfBirth: '12/03/1990',
startYear: 2010,
getName: () => `${this.firstName} ${this['last name']}`,
setName: function(fullname) {
@@ -15,11 +17,21 @@ const employee = {
console.log(this)
this.firstName = words[0] || ''
this['last name'] = words[1] || ''
}
},
getYears(){
let years = 2019 - this.startYear
return years
}
}

const jsonString = JSON.stringify(employee, null, 2)
console.log(jsonString)

employee.setName('Micky Mouse')
console.log(JSON.stringify(employee, null, 2))



console.log(`The employee's name is ${employee.firstName} ${employee['last name']}, ${employee.gender} born on ${employee.dateOfBirth}, started working in this company in ${employee.startYear}.` )

console.log(employee.getName())
console.log(employee.getYears())
@@ -16,6 +16,31 @@ const nums = [5, 8]
const biggest2 = largestNumber(...nums)
console.log(biggest2)

//exercice 1.1.1.1
function multiply(a =1, b =1) {
let total = 0
total = a * b
return total
}

const multiplication = multiply(5, 5)
console.log(multiplication)

const multiplication2 = multiply(5)
console.log(multiplication2)

const multiplication3 = multiply()
console.log(multiplication3)

var squareRoot = (num) => Math.sqrt(num);

const rootOfFour = squareRoot(4)
console.log(rootOfFour)
//end of 1.1.1.1




// example using the arguments object
function add() {
let total = 0
@@ -32,17 +57,10 @@ console.log(addNums)


// example using a rest parameter
function add2(...values) {
let total = 0
console.log(values)
for (let i=0; i<values.length; i++) {
total += values[i]
}
return total
}
var total = 0
var add2 = (... values) => values.reduce((values, total) => { return total += values }, total)

const addNums2 = add2(1, 2, 3, 4)
console.log(addNums2)
console.log(add2(1, 2, 3, 4))


// example with default parameter
@@ -63,16 +81,18 @@ const remainder = function(dividend, divisor) {
return dividend - quotient
}

const rem = remainder(8, 5)
const rem = remainder(4, 2)
console.log(`remainder: ${rem}`)

// function expression using arrow syntax (preferred)
const remainder2 = (dividend, divisor) => {
const quotient = Math.floor(dividend / divisor)
return dividend - quotient
}
const remainder2 = (dividend, divisor, quocient=0) => (dividend - (quocient = Math.floor(dividend / divisor)) * divisor)

console.log(remainder2(5, 2))

//exercice 1.2.1.2
var longestString = (... strings) => strings.reduce((longest, strings) => { return (longest || 0 )> strings ? longest : strings }, 0)

console.log(remainder2(13, 4))
console.log(longestString("dog", "cat", "france"))

// function expression using arrow syntax and one parameter
const sqr = num => num * num
@@ -3,3 +3,4 @@ text
text
Hello world!
Hello world!
Hello world!
@@ -0,0 +1,13 @@
'use strict'

const fs = require('fs')

const jsonQuotes = fs.readFile('quotes.json', (err, data) => {
if (err) throw 'error reading file'
const arrayQuotes = JSON.parse(data)

for(var i in arrayQuotes){
console.log(arrayQuotes[i].quote + "\n")
}
})

@@ -0,0 +1,17 @@
{
"quote1":
{
"quote": "Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it.",
"author": "Steve Jobs"
},
"quote2":
{
"quote": "The best and most beautiful things in the world cannot be seen or even touched - they must be felt with the heart.",
"author": "Helen Keller"
},
"quote3":
{
"quote": "My mission in life is not merely to survive, but to thrive; and to do so with some passion, some compassion, some humor, and some style.",
"author": "Maya Angelou"
}
}
@@ -4,7 +4,7 @@

const request = require('request')

const url = 'https://api.openweathermap.org/data/2.5/weather?q=coventry,uk&appid=44c39f3fa462f86b3fc88f5678e5c5ff'
const url = 'https://api.openweathermap.org/data/2.5/weather?q=coventry,uk&appid=f21d8fc2a9279fdd3a4bc0a250f8c17a'

request(url, (err, response, body) => {
if(err) console.log(err.message)
@@ -22,19 +22,20 @@
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.6",
"bcrypt": "https://github.com/kelektiv/node.bcrypt.js.git#master",
"bcrypt-promise": "^2.0.0",
"fs-extra": "^7.0.1",
"handlebars": "^4.1.2",
"koa": "^2.6.2",
"koa-body": "^4.0.8",
"handlebars": "^4.4.3",
"koa": "^2.10.0",
"koa-body": "^4.1.1",
"koa-bodyparser": "^4.2.1",
"koa-router": "^7.4.0",
"koa-session": "^5.10.1",
"koa-session": "^5.12.3",
"koa-static": "^5.0.0",
"koa-views": "^6.1.5",
"mime-types": "^2.1.22",
"sqlite-async": "^1.0.11"
"koa-views": "^6.2.1",
"mime-types": "^2.1.24",
"python2": "0.0.1",
"sqlite-async": "^1.0.12"
},
"devDependencies": {
"eslint": "^5.15.2",

0 comments on commit bc77be4

Please sign in to comment.