Giter Club home page Giter Club logo

w01d02-hw1's Introduction

Javascript Homework Week1 Homework1

Assignment Operator

Exercise 1:

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:

  • What is a?
a is 'bongos'
  • What is b?
b is 'true'
  • What is c?
c is 'bongos'

Exercise 2:

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:

How can we make num3 equal to the sum of num1 and num2?

// your solution here
let num3 = num1 + num2;

Exercise 3:

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:

// your solution here 
console.log(num1 +" + "+ num2 +" = "+ num3);

Comparisons

Exercise 1:

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:

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

Data Types and Variables

Exercise 1:

  1. Creat a variable called bill and assign it to 10.25 + 3.99 + 7.15 (let JavaScript do the calculation)
  2. Create a vairable called tip and assign it to multiplying bill by 15% tip rate.
  3. Add the bill and tip together and store it into a variable called total.
  4. Print the total to the JavaScript console

Your solution here:

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);

Exercise 2:

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."

  1. Declare a Quotes variable
  2. 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

Your solution here:

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.");

Exercise 3:

Here is a message:
"Hi, my name is Sara. I love cats. In my spare time, I like to watch movies"

  1. Declare and assign values to three variables for each part of the sentence that changes (firstName, interest, and hobby)
  2. Use your variables and string concatenation to create your own message and store it in an message variable
  3. print your message to the JavaScript console.

Your solution here:

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);

Conditionals

Exercise 1:

Write an if...else statement that:

  1. prints "even" if the number is an even number
  2. prints "odd" if the number is an odd number Hint: Use the % (modulo) operator to determine if a number is even or odd.

Your solution here:

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");
}

Exercise2:

Write a series of conditional statements that:

  1. Prints "not a group" if musicians is less than or equal to 0
  2. Prints "solo" if musicians is equal to 1
  3. Prints "duet" if musicians is equal to 2
  4. Prints "trio" if musicians is equal to 3
  5. Prints "quartet" if musicians is equal to 4
  6. 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.

Your solution here:

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!");
}

BONUS

  1. 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);
}
  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
var i;
var num = 9;

var iterations = function(num){
  
  for(i = 0;i<=num;i++){
    console.log(i);
  }
}

iterations(num);

Additional Resources

  1. Variables

  2. Conditions

For more practice read about...

w01d02-hw1's People

Contributors

daghustani avatar fatmake 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.