Day-3 of 30daysofJavascript

·

6 min read

Welcome to Day-3

These are my solution to Exercises in 30-Days-of-Javascript

you have boundless energies, now time to use them

  1. Declare firstName, lastName, country, city, age, isMarried, year variable and assign value to it and use the typeof operator to check different data types.

  2.   //understand difference between let var const
      var firstName = "Isha"; 
      typeof(firstName); //String
      var lastName = "Patel";
      typeof(lastName);//string
      var country = "India";
      typeof(country);//string
      var city = "Raipur";
      typeof(city)//string
      var age = 24;
      typeof(age);//age is just a number
      const isMarried = 0; 
      typeof(isMarried);//number we can write false to make it boolean value
      const year = new Date().getFullYear();
      typeof(year)//number
    
  3. Check if type of '10' is equal to 10. (Type of '10' is string while 10 is number.)

  4. Write three JavaScript statement which provide truthy value.

Any value with "true" boolean value is true as per Javascript. 3>1 or 6>4,

  1. Write three JavaScript statement which provide falsy value.
  • Answer
    2<1 , 7<=3, 56===52.0
  • Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log()

    1. 4 > 3 (True)

    2. 4 >= 3(True)

    3. 4 < 3(False)

    4. 4 <= 3(False)

    5. 4 == 4(True)

    6. 4 === 4(True)

    7. 4 != 4(False)

    8. 4 !== 4(False)

    9. 4 != '4'(True) //False

    10. 4 == '4'(False)//True

    11. 4 === '4'(False)

  • Find the length of python and jargon and make a falsy comparison statement.

"Python".length !="Jargon".length;
  1. Figure out the result of the following expressions first without using console.log(). After you decide the result confirm it by using console.log()

    1. 4 > 3 && 10 < 12 Predicted Answer is written in brackets (true)

    2. 4 > 3 && 10 > 12(False)

    3. 4 > 3 || 10 < 12(True)

    4. 4 > 3 || 10 > 12(True)

    5. !(4 > 3)(False)

    6. !(4 < 3)(True)

    7. !(false) (true)

    8. !(4 > 3 && 10 < 12) (false)

    9. !(4 > 3 && 10 > 12)(true)

    10. !(4 === '4') (true)

Use the Date object to do the following activities

  • What is the year today?

  • What is the month today as a number?

  • What is the date today?

  • What is the day today as a number?

  • What is the hours now?

  • What is the minutes now?

  • Find out the numbers of seconds elapsed from January 1, 1970 to now.

var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;
var date = time.getDate();
var day = time.getDay();
var hours = time.getHours();
var minutes = time.getminutes();
var numberofSeconds = time.getTime()
  1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
let base = prompt("Enter number","Base of triangle");
let height = prompt("Enter number","Height of triangle");
var calculate = base*height*0.5;
  1. Write a script that prompt the user to enter side a, side b, and side c of the triangle and and calculate the perimeter of triangle (perimeter = a + b + c)

    let sideA = prompt("Enter Side A","5");
    let sideB = prompt("Enter Side B","4");
    let sideC = prompt("Enter Side C","12");
    const perimeter = sideA+sideB+sideC;
    
  2. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width))

let length = prompt("Enter length of rectangle");
let width = prompt("Enter Width of rectangle");
var area = length*width;
var perimeter = 2*(length+breadth);
console.log("Area of Rectangle is ${area} while perimeter of rectangle is ${perimeter});
  1. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14.

  2. let radius = prompt("Enter Radius of Circle");
    var area = 3.14*radius*radius;
    var circumference = 2*3.14*radius;
    
  3. Calculate the slope, x-intercept and y-intercept of y = 2x -2

  4. let x = prompt("Value of x");
    var slope1 = 2*x-2;
    
  5. Slope is m = (y2-y1)/(x2-x1). Find the slope between point (2, 2) and point(6,10)

  6. let x1=2;
    let y2=2;
    let x2 = 6;
    let y2 = 10;
    var slope2= (y2-y1)(x2-x1);
    
  7. Compare the slope of above two questions.

  8. const compare = (slope1 === slope2);
    

    Calculate the value of y (y = x2 + 6x + 9). Try to use different x values and figure out at what x value y is 0

  9. let x = prompt("Value of x");
    var calculate = x*x+6*x+9;
    
  10. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?

  11. let hours = prompt("Enter Working hours");
    let rate = prompt("Enter Rate per hour");
    var calculateWeek = hours*rate*7;
    console.log("Your weekly earning is ${calculateWeek}")
    
  12. If the length of your name is greater than 7 say, your name is long else say your name is short.

  13. var myName = "Isha";
    var print = myName.length>7?"Long Name":"Short Name";
    
  14. Compare your first name length and your family name length and you should get this output.

let firstName = 'Isha'
let lastName = 'Patel'
var result = firstName.length>lastName.length?"Your First name,${firstname}is longer than your family name,${lastName}":"Your last name, ${lastName} is longer than your first name, ${firstName}"
Your last name, Patel  is longer than your first name, Isha.
  1. Declare two variables myAge and yourAge and assign them initial values and myAge and yourAge. get the output in the form I am 225 years older than you.

    var myAge = 100;
    var yourAge = 90;
    var calculate = myAge>yourAge?myAge-yourAge:yourAge-myAge;
    var older = myAge>yourAge?"I am ${calculate} years older than you":"You are ${calculate} years older than me";
    

    Using prompt get the year the user was born and if the user is 18 or above allow the user to drive if not tell the user to wait a certain amount of years.

  2. let Age = prompt("What is your Age?");
    var year = 18-Age;
    var calculate = Age>18?"You can drive":"Wait for${year}"
    

14.Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years

var yourAge = prompt("Enter your Age");
var live = new Date().getTime();

Date Time Object Questions

  1. Create a human readable time format using the Date time object

  2. YYYY-MM-DD HH:mm

  3. DD-MM-YYYY HH:mm

  4. DD/MM/YYYY HH:mm

  5. Create a human readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )

  6. YYY-MM-DD HH:mm eg. 20120-01-02 07:05