From ea6d1fecda58f90df69b8ecf32853441847d79b6 Mon Sep 17 00:00:00 2001 From: Tiago Ferreira Date: Thu, 3 Oct 2019 15:22:55 +0100 Subject: [PATCH] 03_10_19 --- exercises/02_http/01_url/index.js | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/exercises/02_http/01_url/index.js b/exercises/02_http/01_url/index.js index c7a9340a..f7127835 100644 --- a/exercises/02_http/01_url/index.js +++ b/exercises/02_http/01_url/index.js @@ -37,19 +37,43 @@ router.get('/anon', ctx => { // anon case }) -router.get('/books/:index', ctx => { - const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden'] +router.get('/books/:index/:index2', ctx => { + const books = ['The Hobbit', 'Alice in Wonderland', 'The Secret Garden', 'The Lord of the Rings'] const parameters = ctx.params console.log(parameters) - const title = books[parameters.index] - ctx.body = title + const title = books[parameters.index] + ' ' + books[parameters.index2] + + if(isNaN(parameters.index) || isNaN(parameters.index2)){ + + ctx.body = 'Indexes arent numbers'; + + } else { + if(Number.isInteger(parameters.index) || Number.isInteger(parameters.index2)){ + + ctx.body = 'Indexes arent integers'; + + } else { + + if(parameters.index <= 3 && parameters.index2 <= 3){ + + ctx.body = title; + } + } + } }) router.get('/name', ctx => ctx.body = JSON.stringify(ctx.query)) router.get('/hello/:name', ctx => { let myname = ctx.params.name - if(ctx.query.format === 'upper') myname = myname.toUpperCase() + if(ctx.query.format === 'lower') myname = myname.toLowerCase() + if(ctx.query.format === 'reverse'){ + + var words = myname.split(' '); + //console.log(words[1]); + var reversed = words.reverse(); + myname = reversed.join(' '); + } // only applies uppercase if formatting query exists ctx.body = `hello ${myname}` })