GithubHelp home page GithubHelp logo

09_javascript_intro_hw's Introduction

Javascript Homework

  1. Variables

  2. Conditions

  3. Functions

Activity Assignment

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' 2. What is b?

b is true
3.  What is `c`?

c is 'bongos'


## Activity 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.

```js
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(firstWord +" "+secondWord +" " + thirdWord + " " + fourthWord)

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?
num3 = num1 + num2
  1. Use variables num1, num2 and num3 to fill in the console.log() to complete the sentence:

console.log(num3 = num1 + num2)

The sum of 5 and 10 is 15

console.log('the sum of ' + num1 + 'and' + num2 'is' + num3)

Activity 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

Activity 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
// your answer here
var userNumber = prompt("enter a number between 0 - 100");

if (userNumber % 5 == 0 && userNumber % 3 == 0) {
  console.log("FizzBuzz");
} else if (userNumber % 5 == 0) {
  console.log("Buzz");
} else if (userNumber % 3 == 0) {
  console.log("Fizz");
} else {
  console.log(userNumber);
}

BONUS

  1. Research a loop so that your condition runs on every number from 0 to 100
// your answer here
for(var userNumber =0 ; userNumber <=100 ; userNumber++){
if (userNumber % 5 == 0 && userNumber % 3 == 0) {
  console.log("FizzBuzz");
} else if (userNumber % 5 == 0) {
  console.log("Buzz");
} else if (userNumber % 3 == 0) {
  console.log("Fizz");
} else {
  console.log(userNumber);
}
    }
  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

function FizzBuzz(Number) { if (Number % 5 == 0 && Number % 3 == 0) { console.log("FizzBuzz"); } else if (Number % 5 == 0) { console.log("Buzz"); } else if (Number % 3 == 0) { console.log("Fizz"); } else { console.log(Number); } }

Additional Resources

For more practice read about...

09_javascript_intro_hw's People

Contributors

marcwright avatar nouras98 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.