File tree Expand file tree Collapse file tree 4 files changed +21
-6
lines changed
Expand file tree Collapse file tree 4 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,26 @@ const eyes = require('eyespect')
44const { data } = require ( '../data/flashcardData.json' )
55const { cards } = data
66
7+ router . get ( '/' , ( req , res ) => {
8+ const numberOfCards = cards . length
9+ const flashcardId = Math . floor ( Math . random ( ) * numberOfCards )
10+
11+ res . redirect ( `/cards/${ flashcardId } ` )
12+ } )
13+
714router . get ( '/:id' , ( req , res ) => {
815 eyes . inspect ( req . query , 'req.query' )
916
1017 const { side } = req . query
1118 const { id } = req . params
19+
20+ if ( ! side ) res . redirect ( `/cards/${ id } ?side=question` )
21+
22+ const name = req . cookies . username
1223 const text = cards [ id ] [ side ]
1324 const { hint } = cards [ id ]
1425
15- const templateData = { id, text }
26+ const templateData = { id, text, name }
1627
1728 if ( side === 'question' ) {
1829 templateData . hint = hint
Original file line number Diff line number Diff line change @@ -6,4 +6,6 @@ block content
66 if hint
77 p
88 i Hint: #{hint}
9- a( href =` /cards/${ id} ?side=${ sideToShow} ` ) = ` ${ sideToShow .charAt (0 ).toUpperCase ()}${ sideToShow .slice (1 )} `
9+ a( href =` /cards/${ id} ?side=${ sideToShow} ` ) = ` ${ sideToShow .charAt (0 ).toUpperCase ()}${ sideToShow .slice (1 )} `
10+ br
11+ a( href ='/cards' ) Next card
Original file line number Diff line number Diff line change @@ -2,7 +2,5 @@ extends layout.pug
22
33block content
44 section#content
5- h2 Welcome, #{name} !
6- form( action ='/goodbye' , method ='POST' )
7- button( type ='submit' ) Goodbye
8-
5+ p
6+ a( href ='/cards' ) Begin!
Original file line number Diff line number Diff line change @@ -4,5 +4,9 @@ html(lang="en")
44 title Flash Cards
55 body
66 include includes/header.pug
7+ if name
8+ h2 Welcome, #{name} !
9+ form( action ='/goodbye' , method ='POST' )
10+ button( type ='submit' ) Goodbye
711 block content
812 include includes/footer.pug
You can’t perform that action at this time.
0 commit comments