console.log('Hi there!'); // Prints: Hi there!
let single = 'Wheres my project code?'; let double = "Wheres my project code?";
let amount = 6; let price = 4.99;
let lateToWork = true;
let x = null;
+ addition - subtraction * multiplication / division % modulo // Addition 5 + 5 // Subtraction 10 - 5 // Multiplication 5 * 10 // Division 10 / 5 // Modulo 10 % 5
let message = 'good night'; console.log(message.length); // Prints: 10 console.log('howdy'.length); // Prints: 5
console.log(Math.random()); // Prints: 0 - 0.9
console.log(Math.floor(5.95)); // Prints: 5
Single Line Comments
// This line will denote a comment
/* The below configuration must be changed before deployment. */
Remainder / Modulo Operator
// calculates # of weeks in a year, rounds down to nearest integer const weeksInYear = Math.floor(365/7); // calcuates the number of days left over after 365 is divded by 7 const daysLeftOver = 365 % 7 ; console.log("A year has " + weeksInYear + " weeks and " + daysLeftOver + " days");
// examples of variables let name = "Mycodetips"; const found = false; var age = 3; console.log(name, found, age); // Mycodetips, false, 3
const numberOfColumns = 4; numberOfColumns = 8; // TypeError: Assignment to constant variable.
let count; console.log(count); // Prints: undefined count = 10; console.log(count); // Prints: 10
+= addition assignment -= subtraction assignment *= multiplication assignment /= division assignment let number = 100; // Both statements will add 10 number = number + 10; number += 10; console.log(number); // Prints: 120
let service = 'credit card'; let month = 'May 30th'; let displayText = 'Your ' + service + ' bill is due on ' + month + '.'; console.log(displayText); // Prints: Your credit card bill is due on May 30th.
const currency = '$'; let userIncome = 85000; console.log(currency + userIncome + ' is more than the average income.'); // Prints: $85000 is more than the average income.