Be Sociable, Share!

martes, 17 de mayo de 2022

Review concepts to keep knowledge fresh: JavaScript

What is the correct way to declare a new variable that you can change? 
>> 
let = myName
Let variable can be changed after they are created

What is the outcome of this statement? 
>> 
3 is printed to the console
What are variables used for in JavaScript? 
>> 
For storing or holding data

What is the outcome of the following code snippet?
console.log('Hello world'); 
>>> 
Hello world is printed to the console

What is the correct way to call the random method on the Math global object?
>> 
Math.random()

What is string interpolation?
>> 
Using template literals to embed variables into strings.

Which of the following code snippets would cause an error?
>> 
const food = 'chicken';
food = 'sushi';

What will the following code print to the console? 
>>
let num = 10;
num *= 3;
console.log(num); 
*= will multiply the num by 3 and then reassign the value of num to that result.

Which of the following is an example of a single line comment?
>>  
// creates a single line comment

What is the correct way to call a string’s built-in method?
>>
'here'.toUpperCase(); is a built-in method.

What is string concatenation? 
>>
String concatenation is the process of joining strings together.
 

Console.log(`My name is ${myName}. I am ${myAgeInDogYears} years old in dog years.`);

//Create a variable named myAge, and set it equal to your age as a number.

const myAge =  20;

//Create a variable named earlyYears and save the value 2 to it. Note, the value saved to this variable will change.

let earlyYears = 2;

earlyYears *= 10.5;

// Since we already accounted for the first two years, take the myAge variable, and subtract 2 from it.Set the result equal to a variable called laterYears. We’ll be changing this value later. 

let laterYears = myAge - 2;

// Multiply the laterYears variable by 4 to calculate the number of dog years accounted for by your later years. Use the multiplication assignment operator to multiply and assign in one step.

laterYears *= 4;

console.log(earlyYears);

console.log(laterYears);

let myAgeInDogYears =  earlyYears + laterYears;

console.log(myAgeInDogYears);

//Write your name as a string, call its built-in method .toLowerCase(), and store the result in a variable called myName.

let myName = "Micamilo".toLowerCase();

console.log(`My name is ${myName}. I am ${myAgeInDogYears} years old in dog years.`);