Work in src/
directory. Ignore other files, just use or create a new js file and solve the following questions in it. Sometimes it might be better to create additional files for different tasks. For example, if you are working on a task that requires a lot of code, you can create a separate file for that task.
Variables; Data Types (number, string, boolean, undefined, null); prompt; comparison and logical operators; type conversion
- Declare a variable and assign a string as a value. Make sure the string is at least 6 characters long. Print the variable to the console.
- What is the difference between "5" and 5?
- Declare a variable and assign a number as a value. Make sure the number is greater than 9. Print the variable to the console.
- Declare a variable and assign a boolean as a value. Print the variable to the console.
- What operators give us a boolean result?
- Declare a variable with the value of "Hello". Covert the value to upper case and print the converted value to the console.
- Declare another variable with the value of "World". Convert the value to lower case and print the converted value to the console.
- Given code:
What is the value of the variable
let text = 'Hello'; text.toUpperCase(); console.log(text);
text
before and after the method is called? - Given code:
What is the value of the variable
let text; console.log(text);
text
? - Find an error in the following code:
let text = 'Hello'; console.log(text.toLowercase());
- Find and fix the error in the following code:
let age = prompt('How old are you?'); let nextAge = age + 1; console.log(`Next year you will be ${nextAge}`);
- Finish the code:
let name = prompt('What is your name?'); let age = Number(prompt('How old are you?')); let isInSixties;// finish the code so that it prints true if the age is in 60s console.log(`${name} is in sixties: ${isInSixties}`);
- What is the value of
x
?let x = 5; console.log(x++); console.log(x);
- What is the value of
y
?let y = 5; console.log(++y); console.log(y);
- What is
x++
andx--
? - What is the difference between
++x
andx++
? - If we try to declare variable without any value, what will be the value of the variable in the console?
- Show the example of equality operator.
- Show the example of not equal operator.
- What's going on when we try to add string and number?