Skip to content

tural-xanaliyev/KodX-JS-lessons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript "if,else if, else" exercises:

Exercise-1: Check if a number is odd or even in JavaScript

Use the “%” operator in the if block to get the type of number.

Alt text

Exercise-2: Find the largest of two number

Print num1 is the largest if num1 > num2 else Print num2 is the largest if num1 < num2. On none true condition print num1 and num2 are equal.

Exercise-3: sort three numbers

In the entry we were given 3 numbers. You must order these numbers from smallest to largest using conditional operators

Exercise-4: Find number of days in a given month

  • If month is outside the range of 1 and 12 print “Invalid month”.
  • If month is equal to 2 ie, February print “29 days” if leap year else print “28 days” .
  • Else if month is equal to 4, 6, 9 or 11 print “30 days”.
  • Else print “31 days”.

Exercise-5: Find the grade for input marks

  • Print “S grade” if marks is between 90 and 100.
  • Print “A grade” if marks is between 80 and 90.
  • Print “B grade” if marks is between 70 and 80.
  • Print “C grade” if marks is between 60 and 70.
  • Print “D grade” if marks is between 50 and 60.
  • Print “E grade” if marks is between 40 and 50.
  • Print “Student has failed” if marks is between 0 and 40.
  • Else print “Invalid marks”.

Exercise-6: Find check if a year is leap year or not

  • If year is divisble by 4 and not divisble by 100 then print “leap year”.
  • Or if year is divisible by 400 then print “leap year”.
  • Else print “not a leap year”.
    2012 //"Year 2012 is a leap year"
    1900 //"Year 1900 is not a leap year"
    2000 //"Year 2000 is a leap year"
    2011 //"Year 2011 is not a leap year"

Exercise-7: Perform arithmetic operations on two numbers

Create 3 variables. Let them be num1, num2 and op. num1 and num2 are our numbers. and op is any arithmetic operator. For example, multiply, divide, subtract, add, modulus

  • Print result of num1+num2 if operation is “add”
  • Print result of num1-num2 if operation is “subtract”
  • Print result of num1*num2 if operation is “multiply”
  • Print result of num1/num2 if operation is “divide”
  • Print result of num1%num2 if operation is “modulus”
  • Else print “Invalid operation”

Exercise-8: Check if a triangle is equilateral, scalene, or isosceles

Create three variables named side1, side2, side3. These variables are the sides of the triangle and simply accept numbers. Find the type of triangle using the “==” and “&&” operators in JavaScript.

- Print “Equilateral triangle.” if values for all side1, side2 and side3 are equal.
- Print “Isosceles triangle.” if values for side1 is equal to side2 or side2 is equal to side3
- Else “Scalene triangle.” since values of all sides are unequal.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published