diff --git a/js/tests/how-2-js_test.js b/js/tests/how-2-js_test.js new file mode 100644 index 000000000..e55fa3714 --- /dev/null +++ b/js/tests/how-2-js_test.js @@ -0,0 +1,16 @@ +import { readFileSync as read } from 'fs' + +// /*/ // ⚡ + +export const tests = [ + ({ eq }) => + eq( + read('/jail/student/index.html', 'utf8').trim(), + '', + ), + ({ eq }) => + eq( + read('/jail/student/hello-world.js', 'utf8').trim(), + `console.log('Hello World')`, + ), +] diff --git a/subjects/how-2-js.en.md b/subjects/how-2-js.en.md new file mode 100644 index 000000000..a6e4cfcd4 --- /dev/null +++ b/subjects/how-2-js.en.md @@ -0,0 +1,45 @@ +## How 2 JS + +### Instructions + +Hello and welcome to the JS piscine, first you will have to learn +to execute javascript. + +Being a special child, JS can run in different **runtime**, what you can +do with it greatly depend of your runtime. + +Luckly you don't need to install anything for that since all you +need is a web browser. + +> Main runtime for executing JS are: any web browser, NodeJS and Deno. + +Let's make a hello world: + +```bash +# first we create the javascript file +echo "console.log('Hello World')" > how-2-js.js + +# To run JS in your browser you need to import it from an HTML page: +echo '' > index.html + +# Finally let's create a simple web server +&>/dev/null python3 -m http.server & + +# Now open your browser at the specified port +xdg-open 'http://localhost:8000' +``` + +> `xdg-open` find your default application for the given argument +> on mac it's just `open` and it's `start` on windows + +You can now open your web browser console (`ctrl`+`shift`+`i`) +and you should see your hello world. + +> The console is a very handy place to test code and explore how the language +> works, don't be shy and play in it ! + +Great ! you are all set, if you want to re-execute your script, just refresh. + +You now just have to create a repository named `piscine-js`, +which will hold all your solutions for this piscine +and just add your 2 generated files to it, we will start slow for now... 🐢