Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RENDU][MTI] tible_p #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions exercises/nodejs/02-interactive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ function tryAgain(callback) {
message: chalk.red('Must be a number between 1 and 100'), // Warning message to display if validation fails.
required: true // If true, value entered must be non-empty.
}], (err, result) => {
if (err) return callback(err);
if (err) return console.log(err);

if (result.value < valueToGuess) {
console.log(chalk.red('Too small !'));
return callback(null, false);
return callback(tryAgain(function(){}), false);
}
else if (result.value > valueToGuess) {
console.log(chalk.red('Too big !'));
return callback(null, false);
return callback(tryAgain(function() {}), false);
}
else {
console.log(chalk.black.bgYellow('You won !'));
Expand Down
9 changes: 8 additions & 1 deletion exercises/nodejs/03-promise/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function askUser() {

// TODO resolve the promise !!!
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
resolve(choices);
});
});
}
Expand All @@ -62,7 +63,13 @@ function fetchData(choices) {

// TODO now use the fetch API :
// https://developer.mozilla.org/fr/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
return Promise.reject(new Error('fetchData not implemented !'));
return fetch(url).then(function(result){
spinner.stop();
if(result.ok)
return result.json();
else
return console.log('ERROR : Network response was not ok.');
});
}

function displayResults(data) {
Expand Down
31 changes: 30 additions & 1 deletion exercises/nodejs/05-express_routing/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,41 @@ const router = module.exports = new express.Router();
/////////////////////////////////////////////

router.get('/', (req, res) => {
res.send('hello from API sub-router !');
res.send(`
<!DOCTYPE html>
<head>
<title>My little API</title>
<style type="text/css">
body {
margin: 40px;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
color: #333;
}
</style>
</head>

<h1>...</h1>
<li><a>${req.baseUrl}/hello</a>
<li><a>${req.baseUrl}/random</a>

<script>
document.querySelector('h1').textContent = document.title;
Array.prototype.forEach.call(document.querySelectorAll('a'), function(el) {
el.href || (el.href = el.text);
});
</script>
`);
// TODO a small page listing your endpoints
// cf. js-class-2016-episode-2\src\server\common\meta-routes.js
});

router.get('/hello', function (req, res) {
res.send("Hello, it's me I was wondering if after all these years You'd like to meet, to go over Everything ...");
});

router.get('/random', function(req, res){
res.send('<iframe width="800" height="600" src="http://lesjoiesducode.fr/random"></iframe>');
});

// TODO one or two routes
// be creative !
Expand Down