- Open your command line and navigate to your
reposdirectory (if you do not have areposfolder, then you can usemkdir reposto create one) - Use this template repository to start a new project in your repos folder:
git clone <repo_name> - cd
repo_nameto navigate into your new repo directory - Start Visual Studio Code and select 'Open Folder'. Then select
repo_nameto 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
watchingand assign it a new promise object - Inside of the promise constructor, declare a variable named
userWatchingLiveStream. - Add a
if/elseconditional that checks ifuserWatchingLiveStreamis true - If
userWatchingLiveStreamis true, call theresolvemethod with "Thumbs up and Subscribe!" - If false, call the
rejectmethod with "User left."
- Once you have created your new promise:
- Call
watchingand add a promise chain using.thenand.catch - Pass in a function callback to
.thenthat takes in a message andconsole.log's the message - Pass in a function callback to
.catchthat takes in an error andconsole.log's the error