Skip to content

Commit

Permalink
Ejercicio Obligatorio Modulo4
Browse files Browse the repository at this point in the history
  • Loading branch information
salvacam committed May 23, 2015
1 parent d412795 commit 5e9e76c
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tema4/ejercicio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
necesario instalar los modulos express y replacestream
npm install express
npm install replacestream
*/

var express = require('express');
var path = require('path');
var app = express();
var fs = require("fs");
var replaceStream = require('replacestream');
var bodyParser = require('body-parser');
var QS = require('querystring'),
e, d;

app.use(bodyParser.urlencoded({
extend: true
}));
app.use(express.static(path.join(__dirname, 'public')));

app.post('/respuesta', function (req, res) {
var respuesta = "";
var salida = "";
if (req.body.pregunta == 1) {
respuesta = req.body.america;
respuesta = respuesta.toLowerCase();
if (respuesta == "cristobal colon" || respuesta == "cristobal colón") {
salida = "Respuesta Correcta!!";
} else {
salida = "Respuesta Incorrecta. Respuesta correcta: Critobal Colón";
}
} else {
if (req.body.pregunta == 2) {
respuesta = req.body.portugal;
respuesta = respuesta.toLowerCase();
if (respuesta == "lisboa") {
salida = "Respuesta Correcta!!";
} else {
salida = "Respuesta Incorrecta. Respuesta correcta: Lisboa";
}
} else {
salida = "no se ha enviado nada";
}
}
res.writeHead(200, {
'Content-Type': 'text/html'
});
fs.createReadStream('public/html/respuesta.html')
.pipe(replaceStream('{{valor}}', salida))
.pipe(res);
});

app.get('/preguntas', function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
fs.createReadStream('public/index.html').pipe(res);
});


app.listen(8000);
49 changes: 49 additions & 0 deletions tema4/public/css/estilos.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
*{
margin: 0;
padding: 0;
}

header {
width: 100%;
height: 75px;
margin: 0 auto;
text-align: center;
background-color: bisque;
}

.header {
width: 300px;
font-size: 1.5em;
line-height: 75px;

margin: 0 auto;
text-align: center;
}

.content {
width: 90%;
margin: 0 auto;
margin-top: 50px;
margin-bottom: 50px;
}

footer {

width: 100%;
height: 100px;
margin: 0 auto;
/*margin-top: 100px;*/
text-align: center;
background-color: dimgray;
color: white;
}

footer .content{

width: 300px;
font-size: 1.5em;
line-height: 100px;

margin: 0 auto;
text-align: center;
}
35 changes: 35 additions & 0 deletions tema4/public/html/respuesta.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<html lang="es">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Node.js</title>
<link rel="stylesheet" href="./css/estilos.css">
</head>

<body>
<header>
<div class="header">
Ejercicio P2P Módulo 4
</div>
</header>


<div class="content">
<h3>Respuesta</h3>

<br/>
{{valor}}
<br/>
<a href="../index.html">Volver</a>
</div>

<footer>
<div class="content">
Curso Node.js
</div>
</footer>

</body>
</html>
70 changes: 70 additions & 0 deletions tema4/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!doctype html>
<html lang="es">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Node.js</title>
<link rel="stylesheet" href="./css/estilos.css">
</head>

<body>
<header>
<div class="header">
Ejercicio P2P Módulo 4
</div>
</header>


<div class="content">
<h3>Responde a una de las dos preguntas</h3>
<br/>
<form method="post" action="respuesta" id="enviar1">
<label for="america">
¿Quién descubrio América?
</label>
<input name="america" id="america" type="text" />
<input type="hidden" name="pregunta" value="1" />

<input type="submit" value="Enviar Respuesta" />
</form>

<br/>

<form method="post" action="respuesta" id="enviar2">
<label for="portugal">
¿Cuál es la cápital de Portugal?
</label>
<input name="portugal" id="portugal" type="text" />
<input type="hidden" name="pregunta" value="2" />

<input type="submit" value="Enviar Respuesta" />
</form>
</div>

<footer>
<div class="content">
Curso Node.js
</div>
</footer>
<script>
var enviar1 = document.getElementById("enviar1");
enviar1.addEventListener("submit", function (e) {
if (document.getElementById("america").value.trim() == "" ||
document.getElementById("america").value.trim() == undefined) {
alert("valores vacios");
e.preventDefault();
}
});
var enviar2 = document.getElementById("enviar2");
enviar2.addEventListener("submit", function (e) {
if (document.getElementById("portugal").value.trim() == "" ||
document.getElementById("portugal").value.trim() == undefined) {
alert("valores vacios");
e.preventDefault();
}
});
</script>
</body>

</html>

0 comments on commit 5e9e76c

Please sign in to comment.