Commit 3e4754c9 authored by Susanne Raml's avatar Susanne Raml
Browse files

Add exercises

parent d3d6ab02
......@@ -9,6 +9,21 @@ mockServer.listen();
const callbackFetch = require("../../../utils/callback-fetch");
// 📝 Start writing here -----------------------------------------------------
const args = process.argv.slice(2);
const storedResponses = [];
args.map(url => {
callbackFetch(url, null, (error, response) => {
if(error) {
return;
}
storedResponses.push(response.body.length);
console.log(args.length);
console.log(args.length);
if(args.length === storedResponses.length) console.log(storedResponses);
});
});
// ⛔️ Stop writing here ----------------------------------------------------
......
"use strict";
const fs = require("fs");
const marked = require("marked");
const html = marked('# Marked in Node.js\n\nRendered by **marked**.');
const args = process.argv.slice(2);
if(args.length == 0) throw Error("Error: no param");
if(args.length == 1) throw Error("Error: one param");
// `marked` and `marked-terminal` have already been installed
// for you. You can import them and start working with them directly.
const inputFile = args[0];
const outputFile = args[1];
fs.readFile(inputFile, (err, content) => {
if (err) throw err;
const htmlCont = marked(content.toString());
fs.writeFile(outputFile, htmlCont, err => {
if(err) throw err;
});
console.log("Done!");
});
\ No newline at end of file
<p><a href="https://example.com">markdown</a></p>
<blockquote>
<p>blockquote</p>
</blockquote>
"use strict";
const { throws } = require("assert");
const { EROFS } = require("constants");
const EventEmitter = require("events");
/**
* You have to finish the implementation of car
*/
class Car {
class Car extends EventEmitter{
constructor() {
super();
this.speed = 0;
}
decelerate() {
this.emit('decelerate');
this.speed -= 10;
this.emit('speedChange', this.speed);
}
accelerate() {
this.emit('accelerate');
this.speed += 10;
this.emit('speedChange', this.speed);
if (this.speed > 100) {
this.emit('error', Error());
}
}
}
......
......@@ -3,10 +3,7 @@
/**
* You have to finish the implementation of OddNumberStream
*/
const {
Readable
} = require("stream");
const { Readable } = require("stream");
function isOdd(num) {
return num % 2 === 1;
......@@ -21,9 +18,23 @@ function findNextOddNumber(begin) {
return findNextOddNumber(begin);
}
class OddNumberStream{
class OddNumberStream extends Readable{
constructor(opt = {}) {
super(opt);
this._max = 100;
this._i = 0;
}
_read() {
this._i = findNextOddNumber(this._i);
if (this._i > this._max) {
this.push(null);
return;
}
const str = String(this._i);
const buf = Buffer.from(str, "ascii");
this.push(buf);
}
}
......
[ 'usr/bin/node',
'/path/to/app.js',
'https://hs-augsburg.de',
'https://nodeschool.io',
'https://peerigon.com' ]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment