diff --git a/README.md b/README.md index f229958..24d7cd3 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,21 @@ -Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js -=== - -Due: September 8th, by 11:59 AM. - -This assignment aims to introduce you to creating a prototype two-tiered web application. -Your application will include the use of HTML, CSS, JavaScript, and Node.js functionality, with active communication between the client and the server over the life of a user session. - -Baseline Requirements ---- - -There is a large range of application areas and possibilities that meet these baseline requirements. -Try to make your application do something useful! A todo list, storing / retrieving high scores for a very simple game... have a little fun with it. - -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete (complete at least two) data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset -- the `Derived field` for a new row of data must be computed based on fields already existing in the row. -For example, a `todo` dataset with `task`, `priority`, and `creation_date` may generate a new field `deadline` by looking at `creation_date` and `priority` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application -- A results page displaying all data currently available on the server. You will most likely use a `` tag for this, but `
+ + + + + + +
Name Type Strong Against Weak To
diff --git a/server.improved.js b/server.improved.js index 26673fc..99ee4a5 100644 --- a/server.improved.js +++ b/server.improved.js @@ -6,10 +6,36 @@ const http = require( 'http' ), dir = 'public/', port = 3000 +const starters = [ + { 'pokémon': 'bulbasaur', 'type': "Grass",}, + { 'pokémon': 'squirtle', 'type': "Water"}, + { 'pokémon': 'charmander', 'type': "Fire"}, + { 'pokémon': 'pikachu', 'type': "Electric"}, + { 'pokémon': 'chikorita', 'type': "Grass",}, + { 'pokémon': 'totodile', 'type': "Water"}, + { 'pokémon': 'cyndaquil', 'type': "Fire"}, + { 'pokémon': 'treeko', 'type': "Grass",}, + { 'pokémon': 'mudkip', 'type': "Water"}, + { 'pokémon': 'torchic', 'type': "Fire"}, + { 'pokémon': 'turtwig', 'type': "Grass",}, + { 'pokémon': 'piplup', 'type': "Water"}, + { 'pokémon': 'chimchar', 'type': "Fire"}, + { 'pokémon': 'snivy', 'type': "Grass",}, + { 'pokémon': 'oshawott', 'type': "Water"}, + { 'pokémon': 'tepig', 'type': "Fire"}, + { 'pokémon': 'chespin', 'type': "Grass",}, + { 'pokémon': 'froakie', 'type': "Water"}, + { 'pokémon': 'fennekin', 'type': "Fire"}, + { 'pokémon': 'rowlet', 'type': "Grass",}, + { 'pokémon': 'popplio', 'type': "Water"}, + { 'pokémon': 'litten', 'type': "Fire"}, + { 'pokémon': 'grookey', 'type': "Grass",}, + { 'pokémon': 'sobble', 'type': "Water"}, + { 'pokémon': 'scorbunny', 'type': "Fire"} +] + const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} + ] const server = http.createServer( function( request,response ) { @@ -38,12 +64,92 @@ const handlePost = function( request, response ) { }) request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) - // ... do something with the data here!!! - + let data = JSON.parse( dataString ) + + switch ( data.type.toLowerCase()){ + case "normal": + data.str = "None" + data.wk = "Fighting" + break + case "fire": + data.str = "Grass, Ice, Bug, Steel" + data.wk = "Water, Ground, Rock" + break + case "water": + data.str = "Fire, Ground, Rock" + data.wk = "Electric, Grass" + break + case "electric": + data.str = "Water, Flying" + data.wk = "Ground" + break + case "grass": + data.str = "Water, Ground, Rock" + data.wk = "Fire, Ice, Poison, Flying, Bug" + break + case "ice": + data.str = "Grass, Ground, Flying, Dragon" + data.wk = "Fire, Fighting, Rock, Steel" + break + case "fighting": + data.str = "Normal, Ice, Rock, Dark, Steel" + data.wk = "Flying, Psychic, Fairy" + break + case "poison": + data.str = "Grass, Fairy" + data.wk = "Ground, Psychic" + break + case "ground": + data.str = "Fire, Electric, Poison, Rock, Steel" + data.wk = "Water, Grass, Ice" + break + case "flying": + data.str = "Grass, Fighting, Bug" + data.wk = "Electric, Ice, Rock" + break + case "psychic": + data.str = "Fighting, Poison" + data.wk = "Bug, Ghost, Dark" + break + case "bug": + data.str = "Grass, Psychic, Dark" + data.wk = "Fire, Flying, Rock" + break + case "rock": + data.str = "Fire, Ice, Flying, Bug" + data.wk = "Water, Grass, Fighting, Ground, Steel" + break + case "ghost": + data.str = "Psychic, Ghost" + data.wk = "Ghost, Dark" + break + case "dragon": + data.str = "Dragon" + data.wk = "Ice, Dragon, Fairy" + break + case "dark": + data.str = "Psychic, Ghost" + data.wk = "Fighting, Bug, Fairy" + break + case "steel": + data.str = "Ice, Rock, Fairy" + data.wk = "Fire, Fighting, Ground" + break + case "fairy": + data.str = "Fighting, Dragon, Dark" + data.wk = "Poison, Steel" + break + default: + data.type = "???" + data.str = "???" + data.wk = "???" + break + } + + appdata.push(JSON.stringify( data )) response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end() + response.end( JSON.stringify( data ) ) }) } diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml new file mode 100644 index 0000000..43c1986 --- /dev/null +++ b/shrinkwrap.yaml @@ -0,0 +1,15 @@ +dependencies: + mime: 2.6.0 +packages: + /mime/2.6.0: + dev: false + engines: + node: '>=4.0.0' + hasBin: true + resolution: + integrity: sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg== +registry: 'https://registry.npmjs.org/' +shrinkwrapMinorVersion: 9 +shrinkwrapVersion: 3 +specifiers: + mime: ^2.4.4