Date of Tomorrow

JavaScriptJavaScriptBeginner
Practice Now

This tutorial is from open-source community. Access the source code

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL javascript(("`JavaScript`")) -.-> javascript/BasicConceptsGroup(["`Basic Concepts`"]) javascript/BasicConceptsGroup -.-> javascript/variables("`Variables`") javascript/BasicConceptsGroup -.-> javascript/data_types("`Data Types`") javascript/BasicConceptsGroup -.-> javascript/arith_ops("`Arithmetic Operators`") javascript/BasicConceptsGroup -.-> javascript/comp_ops("`Comparison Operators`") subgraph Lab Skills javascript/variables -.-> lab-28249{{"`Date of Tomorrow`"}} javascript/data_types -.-> lab-28249{{"`Date of Tomorrow`"}} javascript/arith_ops -.-> lab-28249{{"`Date of Tomorrow`"}} javascript/comp_ops -.-> lab-28249{{"`Date of Tomorrow`"}} end

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:

  1. Use the Date constructor to get the current date.
  2. Increment it by one using Date.prototype.getDate().
  3. Set the value to the result using Date.prototype.setDate().
  4. Use Date.prototype.toISOString() to return a string in yyyy-mm-dd format.

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.

Other JavaScript Tutorials you may like