Introduction
In this lab, we will explore basic JavaScript programming concepts and syntax. We will learn how to create variables, use operators, write functions, and manipulate data types. By the end of this lab, you will have a solid foundation in JavaScript programming that will serve as a basis for more advanced web development topics.
Obtaining Tomorrow's Date
To practice coding, you may begin by opening the Terminal/SSH and typing node. Once you have done this, you can obtain tomorrow's date with the following steps:
- Use the
Dateconstructor to get the current date. - Increment it by one using
Date.prototype.getDate(). - Set the value to the result using
Date.prototype.setDate(). - Use
Date.prototype.toISOString()to return a string inyyyy-mm-ddformat.
Here is the code you can use:
const tomorrow = () => {
let currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);
return currentDate.toISOString().split("T")[0];
};
Once you have entered this code, you can obtain tomorrow's date by calling the function tomorrow(). For example, if today's date is 2018-10-18, the output will be 2018-10-19.
Summary
Congratulations! You have completed the Date of Tomorrow lab. You can practice more labs in LabEx to improve your skills.