- Open your command line and navigate to your
repos
directory (if you do not have arepos
folder, then you can usemkdir repos
to create one) - Use this template repository to start a new project in your repos folder:
git clone <repo_name>
- cd
repo_name
to navigate into your new repo directory - Start Visual Studio Code and select 'Open Folder'. Then select
repo_name
to open the folder in the editor (or just typecode .
in your terminal inside the repo directory) - Follow the instructions on the README.md file to complete exercises
- Open the app.js file to get started
function watchTurorialCallback(callback, errorCallback) {
let userLeft = false;
let userWatchingLiveStream = true;
if (userLeft) {
errorCallback({
name: "User Left",
message: ":(",
});
} else if (userWatchingLiveStream) {
callback("Thumbs up and Subscribe");
}
}
watchTurorialCallback(
(message) => {
console.log(message);
},
(error) => {
console.log(error.name + " " + error.message);
}
);
- The above function can be replicated as a Promise.
- Declare a variable
watching
and assign it a new promise object - Inside of the promise constructor, declare a variable named
userWatchingLiveStream
. - Add a
if/else
conditional that checks ifuserWatchingLiveStream
is true - If
userWatchingLiveStream
is true, call theresolve
method with "Thumbs up and Subscribe!" - If false, call the
reject
method with "User left."
- Once you have created your new promise:
- Call
watching
and add a promise chain using.then
and.catch
- Pass in a function callback to
.then
that takes in a message andconsole.log
's the message - Pass in a function callback to
.catch
that takes in an error andconsole.log
's the error