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
numberand assign it the value 10. - Increment the
numbervariable using both++and+=. - Add 5 to the
numbervariable. - Subtract 2 from the
numbervariable. - Multiply the
numbervariable by 3. - Divide the
numbervariable by 2. - Print
numberusing console.log.
String Operations
- Declare a variable named
textand assign it the value “test”. - Print
textusing console.log. - Declare another variable named
text2and assign it the value oftestin uppercase. - Print
text2using console.log. - Declare a variable called
countand assign it the value 10. - Using a template string, create a variable
templatethat reads “There are a total of 10 items”. - Print
templatewith console.log.
Boolean Variable
- Declare a Boolean variable named
isTrueand set its value totrue. - Print
isTrueusing console.log.
Date Variable
- Declare a variable named
currentDateand set its value to the current date and time. - Print
currentDateusing 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);