Skip to content

ksaninja/hw-week_01-day_02-javascript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Javascript Homework

  1. Variables

  2. Conditions

Assignment Operator

Without running the following code, try to determine:

let a = 1;
let b = 'bongos';
let c = true;

a = b;
b = c;
c = a;

Your solution here:

  1. What is a?
a is ... bongos
  1. What is b?
b is ... true
  1. What is c?
c is ... bongos

Concatenation

Use the + operator to concatenate these strings together within a console.log(): "Please", "squeeze", "the", "cheese". Make sure there are spaces in-between each word.

const firstWord = "Please";
const secondWord = "squeeze";
const thirdWord = "the";
const fourthWord = "cheese";

Result should be:

"Please squeeze the cheese"

Your solution here:

  1. Fill in the console.log()?
console.log("please" + " " + "squeeze" + " " + "the" + " " + "cheese")

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;

Your solution here:

  1. How can we make num3 equal to the sum of num1 and num2?
let num1 = 5
let num2 = 10
 num3 = num1 + num2
  1. Use variables num1, num2 and num3 to fill in the console.log() to complete the sentence:

The sum of 5 and 10 is 15

let num1 = 5
let num2 = 10
let num3 = num1 + num2
console.log(num1 + "+" + num2 + "=" + num3)

Comparisons

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

Your solution here:

  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

Conditionals

Declare a variable equal to a number 0 to 100

Write a conditional statement that...

  • If it is a multiple of 3, print “Fizz” instead of the number.
  • If it is a multiple of 5, print “Buzz” instead of the number.
  • If it is a multiple of both 3 and 5, print “FizzBuzz” instead of the number.
  • Otherwise, print the number

Your solution here:

  1. Write your javascript solution below
let a = 15;
if ( a % 3 === 0 && a % 5 ===0 ) {
     console.log("fizzbuzz");
}
else if ( a % 3 === 0 ) {
     console.log("fizz");
} 
else if ( a % 5 === 0 ) {
     console.log("buzz");
} 
else {
    console.log("a");
}

BONUS

  1. Research a loop so that your condition runs on every number from 0 to 100
1)
do {
alert (d);
d++;}
while (d <= 100);
100

2)
for (let s = 0; s <= 100; ++s)
{alert(s);}
alert (s);

3)
let t = 0;
while (t<=100) {
alert(t);
t++;
}
  1. Research a function so that your condition runs on every number from 0 to whatever number is passed into the function
// your answer here

Additional Resources

For more practice read about...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published