Without running the following code, try to determine:
let a = 1;
let b = 'bongos';
let c = true;
a = b;
b = c;
c = a;
- What is
a
?
a is 'bongos'
- What is
b
?
b is 'true'
- What is
c
?
c is 'bongos'
Output a console log The sum of 5 and 10 is 15
where the values for 5 and 10 are saved to variables, and where 15 comes from those variables being summed.
const num1 = 5;
const num2 = 10;
How can we make num3
equal to the sum of num1
and num2
?
// your solution here
let num3 = num1 + num2;
Use variables num1
, num2
and num3
to fill in the console.log()
to complete the sentence:
The sum of 5 and 10 is 15
// your solution here
console.log(num1 +" + "+ num2 +" = "+ num3);
By just looking at the following expressions, determine in your mind whether or not each will evaluate to true or false
a) 999 > 999
b) 999 === 999
c) 999 !== 999
d) -5 >= -4
e) 100 <= -100
f) 20 + 5 < 5
g) 81 / 9 === 9
h) 9 !== 8 + 1
Write true
or false
based on the list above
a) false
b) true
c) false
d) false
e) false
f) false
g) true
h) false
- Creat a variable called bill and assign it to 10.25 + 3.99 + 7.15 (let JavaScript do the calculation)
- Create a vairable called tip and assign it to multiplying bill by 15% tip rate.
- Add the bill and tip together and store it into a variable called total.
- Print the total to the JavaScript console
Write your javascript solution below
// your answer here
let bill = 10.25 + 3.99 + 7.15;
let tip = bill * 0.15;
let total = bill + tip;
console.log("Total = "+ total);
Use the adjective variables below to fill in the blanks and complete the following message.
"Success is no accident. It is _________, _________, _________, _________, _________ and most of all, _________ of what you are doing or learning to do."
- Declare a Quotes variable
- Use the adjective1, adjective2, adjective3, adjective4 adjective5 and adjective6 variables to set the Quotes variable to the message: "Success is no accident. It is Hard Work, Perseverance, Learning, Studying, Sacrifice and most of all, Love of what you are doing or learning to do."
var adjective1 = "Hard Work";
var adjective2 = "Perseverance";
var adjective3 = "Learning";
var adjective4 = "Studying";
var adjective5 = "Sacrifice";
var adjective6 = "Love";
Assign the resulting string to a variable called Quotes
Write your javascript solution below
// your answer here
var quotes = console.log("Success is no accident. It is "+adjective1+", "
+adjective2+", "+adjective3+", "
+adjective4+", "+adjective5+" and most of all, "
+adjective6+" of what you are doing or learning to do.");
Here is a message:
"Hi, my name is Sara. I love cats. In my spare time, I like to watch movies"
- Declare and assign values to three variables for each part of the sentence that changes (firstName, interest, and hobby)
- Use your variables and string concatenation to create your own message and store it in an message variable
- print your message to the JavaScript console.
Write your javascript solution below
// your answer here
var firstName = "Fatma";
var interest = "Art";
var hobby = "designing";
var message = "Hi, my name is "+firstName+". I love "+interest+" field. In my spare time, I like "+hobby+" User Interfaces";
console.log(message);
Write an if...else statement that:
- prints "even" if the number is an even number
- prints "odd" if the number is an odd number Hint: Use the % (modulo) operator to determine if a number is even or odd.
Write your javascript solution below
// your answer here
var num = 5;
if(num % 2 == 0){
console.log(num+" Is Even");
}else if(num % 2 == 1){ //it'll give the same result if we removed if(num % 2 == 1),using the else alone
console.log(num+" Is Odd");
}
Write a series of conditional statements that:
- Prints "not a group" if musicians is less than or equal to 0
- Prints "solo" if musicians is equal to 1
- Prints "duet" if musicians is equal to 2
- Prints "trio" if musicians is equal to 3
- Prints "quartet" if musicians is equal to 4
- Prints "this is a large group" if musicians is greater than 4 ex If musicians equals 3, then "trio" should be printed to the console.
Write your javascript solution below
// your answer here
var musicians = 3;
if(musicians <= 0){
console.log("not a group");
}
else if(musicians == 1){
console.log("Solo");
}
else if(musicians == 2){
console.log("duet");
}
else if(musicians == 3){
console.log("Trio");
}
else if(musicians == 4){
console.log("Qurtet");
}
else if(musicians > 4){
console.log("This is a large group!");
}
- Research a loop so that your condition runs on every number from 0 to 100
// your answer here
var i;
for(i = 0;i<=100;i++){
console.log(i);
}
- Research a function so that your condition runs on every number from 0 to whatever number is passed into the function
// your answer here
var i;
var num = 9;
var iterations = function(num){
for(i = 0;i<=num;i++){
console.log(i);
}
}
iterations(num);
-
Variables
- https://www.youtube.com/watch?v=cXUWYZXru6o (7 min video)
- https://www.codeanalogies.com/jsconstruction/ (interactive game)
-
Conditions
For more practice read about...