@ -54,7 +54,7 @@ All errors will print a specific message on **stderr** (ending with a newline) a
- Wrong number of arguments: `"Error: expect 1 argument only!"`, exit with `1`.
- If the student grade is not a number or is greater than 100: `Error: The grade "grade" is not a valid input. Only numerical grades between 0 and 100 are accepted.`, exit with `1`.
- If the student grade is not a number or is greater than 100: `Error: The grade <grade> is not a valid input. Only numerical grades between 0 and 100 are accepted.`, exit with `1`.
Create a script `in-back-ground.sh` which will execute a job in the background that will do the following:
- Run the command `cat` on the file "facts" which will read the contents of the file and print it to `stdout`.
- Run the command `cat` on the file [facts](../../../sh/tests/left/facts) which will read the contents of the file and print it to `stdout`.
- The output of the cat command will be piped to the `grep` command, which will search for the string `"moon"` in the file.
- If the `grep` command succeeds (if it finds the string "moon"), you will print `"The moon fact was found!"` to the `output.txt` file. If it fails the file `output.txt` is not created.
- If the command finds the string "moon", it will print the matching line to the `stdout`.
- If the `grep` command succeeds (if it finds the string "moon"):
- You will print `"The moon fact was found!"` to the `output.txt` file. If it fails the file `output.txt` is not created.
- You will should also print the line which contains the string to the `stdout`.
- Redirect the `stdout` to a new file `output.txt`.
You must do all these steps running only one job and using the command `nohup`!
@ -6,12 +6,13 @@ In this exercise you are going to create a guessing game.
Create the script `joker-num.sh` which will receive the number to guess as argument. The number should be between 1 and 100 (inclusive). The player will then have 5 tries to guess the number.
To achieve this you will have to use a `for` loop.
When guessing a valid number the output will be:
When you're trying to guess the secret number with a valid input, your program must output some tips as follow:
- Number bigger than the secret one: `Go down`.
- Number smaller than the secret one: `Go up`.
- Number equal than the secret one: `Congratulations, you found the number!`.
- Ran out of tries: `You lost, the number was <number>`.
- First you will need to prompt a message so that the player knows what he must do: `"Enter your guess (<tries_left> tries left)`.
- If the number is bigger than the secret one: `Go down`.
- If the number si smaller than the secret one: `Go up`.
- If the number is the correct one: `Congratulations, you found the number in <number_of_tries> moves!`.
- If you ran out of tries: `You lost, the number was <number>`.
### Usage
@ -35,8 +36,8 @@ $
### Error handling
- Wrong number of arguments or number not between `1` and `100`: The program will print `Error: wrong argument` and return`1`.
- The player writing something that is not a valid number as an answer: The program will ask again to enter a guess and the number of tries won't be decremented.
- If the player enters the wrong number of arguments or the number is not between `1` and `100`, the program will print `Error: wrong argument` and exit with`1`.
- If the player is writing something that is not a valid number as an answer, the program will ask again to enter a new a guess and the number of tries won't be decremented.
- Asynchronous behavior, in the context of server-side JavaScript, refers to the ability of running code in a non-blockingly way, meaning for instance that the server can handle multiple requests simultaneously without waiting for a long-running task to complete, avoiding blocking the server responsiveness. It is essential to achieve scalable and functional back-end Node applications.
- Asynchronous behavior, in the context of server-side JavaScript, refers to the ability of running code in a non-blocking way, meaning for instance that the server can handle multiple requests simultaneously without waiting for a long-running task to complete, avoiding blocking the server responsiveness. It is essential to achieve scalable and functional back-end Node applications.
- A `Promise` is a special JS object that represent the result (succes or failure) of an asynchronous operation. This special object is usually used to "wrap" asynchronous operations.
- A `Promise` is a special JS object that represent the result (success or failure) of an asynchronous operation. This special object is usually used to "wrap" asynchronous operations.
`Promise`s can have three different states: _pending_ - the asynchronous operation has not finished yet, _fulfilled_/_resolved_ - the asynchronous operation has finished successfully - or _rejected_ - the asynchronous operation has finished, but something went wrong. When defined from scratch, it is possible to define a `resolve` and `reject` callback function for a new `Promise` that will define the results of the success or failure of asynchronous operation happening inside the `Promise`.
- It is possible to wait for an asynchronous function with the keyword `await`. Alternatively, it can be clearer to use the method `.then`. Below an example of how to handle promises and, more generally, asynchronous operations.