Skip to content

J010 Variables

A very simple task related to variables in ES (ECMAScript).

Create an empty app.js and:

  • Start with “use strict”.

Number Operations

  • Declare a variable named number and assign it the value 10.
  • Increment the number variable using both ++ and +=.
  • Add 5 to the number variable.
  • Subtract 2 from the number variable.
  • Multiply the number variable by 3.
  • Divide the number variable by 2.
  • Print number using console.log.

String Operations

  • Declare a variable named text and assign it the value “test”.
  • Print text using console.log.
  • Declare another variable named text2 and assign it the value of test in uppercase.
  • Print text2 using console.log.
  • Declare a variable called count and assign it the value 10.
  • Using a template string, create a variable template that reads “There are a total of 10 items”.
  • Print template with console.log.

Boolean Variable

  • Declare a Boolean variable named isTrue and set its value to true.
  • Print isTrue using console.log.

Date Variable

  • Declare a variable named currentDate and set its value to the current date and time.
  • Print currentDate using console.log.
Solution
"use strict";

// Number Operations
let number = 10;
number++;
number += 1;
number += 5;
number -= 2;
number *= 3;
number /= 2;
console.log(number);

// String Operations
let text = "test";
console.log(text);

let text2 = text.toUpperCase();
console.log(text2);

let count = 10;
let template = `There are a total of ${count} items`;
console.log(template);

// Boolean Variable
let isTrue = true;
console.log(isTrue);

// Date Variable
let currentDate = new Date();
console.log(currentDate);