Git Product home page Git Product logo

booleans-comparisons-conditionals's Introduction

Booleans-Comparisons-Conditionals

Week 1 - Booleans, Comparisons, and Conditionals

Basic Requirments

1.Type the two boolean values -- true and false -- into your console.

2.Use the console to accomplish the following:

 Write an expression using > that will evaluate to false 
 Write an expression using > that will evaluate to true 
 Write an expression using < that will evaluate to false 
 Write an expression using < that will evaluate to true 
 Write an expression using two numbers and === that will evaluate to true 
 Write an expression using two numbers and === that will evaluate to false 
 Write an expression using two strings and === that will evaluate to true 
 Write an expression using two strings and === that will evaluate to false

3.Fill in the ??? with the following operators or values to make the statements output the expected Boolean value.

 12 ??? 78 
 // => true 
 24 ??? 16 
 // => false 
 45 !== ??? 
 // => true 
 '45' ??? 45 
 // => false '6' ??? 'six' 
 // => true

4.In the USA, you can learn to drive when you are 16. Write a function oldEnoughToDrive that takes an age as an argument and returns true if the person with that age is old enough to drive.

5.There is an easy way to figure out how long a string is by adding .length to the end of it. Try this out in the console:

 'hello'.length; 
 ''.length; 
 'Yasser al-Azma'.length;

6.Write a function sameLength that accepts two strings as arguments, and returns true if those strings have the same length, and false otherwise.

7.Write a function passwordLongEnough that accepts a 'password' as a parameter and returns true if that password is long enough -- you get to decide what constitutes long enough.

8.Write a function rentalCar that accepts a person's name and age as arguments, and returns either 'You cannot have the keys, .', or 'Have fun driving, !' depending on whether or not the person is old enough. In the US, most rental car companies do not allow you to rent a car until you are 21.

9.Write a function max that takes two numbers as arguments, and returns the larger one.

10.Write a function min that takes two numbers as arguments, and returns the smaller one.

11.Write functions larger and smaller that each accept two strings as arguments, and return the larger and smaller strings, respectively

More Practice

1.Fill in the ??? with the following operators or values to make the statements output the expected Boolean value!

 106 ??? 12 
 // => false 
 'wiz' ??? 'wiz' 
 // => true 
 7 * 7  ??? 49 
 // => true 
 12 ??? (24 / 2) 
 // => false 
 (20 % 2) <= ??? 
 // => true 
 (9 / 3) + (5 * 5) === ??? 
 // => true

2.Write the functions described below. Each must take one number as an argument:

 even: returns true if its argument is even, and false if odd. 
 odd: the opposite of the above. 
 positive: returns true if its argument is positive, and false if negative. 
 negative: the opposite of the above.

3.A few other useful built-in mathematical functions are Math.random, Math.floor and Math.ceil. Look at these functions on MDN to learn how they work, and use them to implement the following functions:

 randInt: Should accept one numeric argument (n), and return a number from 0 to n - 1. 
 guessMyNumber: Should accept a single numeric argument and compare it to a random number between 0 and 5. It should return one of the following strings: 
       'You guessed my number!' if the argument matches the random number. 
       'Nope! That wasn't it!' if the argument did not match the random number.

Advanced

1.Read more about the difference between using == and ===

2.Read more about data types (as values) in javascript comparing to another langagues

3.With your pair, solve the following riddles without using any help from google!

 I’m tall when I’m young and I’m short when I’m old. What am I? 
 
 In a one-story pink house, there was a pink person, a pink cat, a pink fish, a pink computer, a pink chair, a pink table, a pink telephone, a pink shower– everything was pink!What color were the stairs?
  
 What is at the end of a rainbow?
 You draw a line. Without touching it, how do you make the line longer?
  
 You walk across a bridge and you see a boat full of people yet there isn’t a single person on board. How is that possible? 
 
 If there are 3 apples and you take away 2, how many do you have? 
 
 What do the numbers 11, 69, and 88 all have in common? 
 
 I am an odd number. Take away one letter and I become even. What number am I? 
 
 Using only addition, how do you add eight 8’s and get the number 1000? 
 
 What never asks questions but is often answered?

booleans-comparisons-conditionals's People

Contributors

abdelsalamshahlol avatar

Watchers

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