JavaScript Practice Exercise Four

Question 1 :
Create a variable myName and assign it value TechTIME use a built-in function to show the output in alert box.

let myName = "TechTIME";
alert(myName );

Question 2 :
Create a variable named score, assign value 90 to it and use built-in function to display output You have scored 90% in exams in console.

let score = 90
console.log( 'You have scored',score+ '% in exams' )

Question 3 :
Create a variable name and assign it value Iftikhar, another variable surname and assign it value Umrani and a variable of age and assign value 55. Show following output to console.

My friend Iftikhar Umrani is 55 years old


let name = 'Iftikhar'
let surname = 'Umrani'
let age = 55
console.log('My friend',name,surname,'is',age,'years old')

Question 4 :
Create a variable named channel and store value techTIME . Create another variable named mylist = ['Chicken','Milk','Vegitable','Flour'] use a built-in function/property to show datatype of both variables in console.

let channel = 'TechTIME';
let mylist = ['Chicken','Milk','Vegitable','Flour'];
console.log( typeof channel );
console.log( typeof mylist );

Output:
            'string'
            'array'
          
Question 5 :
Create a program that asks the user to input ages of badal, mateen and shahnawaz. If user inputs age of Badal as 19 and Mateen and Shahnawaz as 18. Show following output using comparison operators.

  • Mateen is younger than Badal
  • Badal is older than Mateen
  • Mateen and Shahnawaz are same age


let ageBadal = prompt('Enter the age of Badal')
let ageMateen = prompt('Enter the age of Mateen')
let ageShahnawaz = prompt('Enter the age of Shahnawaz')

if (ageMateen < ageBadal ) {
   console.log('Mateen is younger than Badal')
}
if (ageBadal > ageMateen) {
   console.log('Badal is older than Mateen')
}
if (ageShahnawaz == ageMateen) {
   console.log('Mateen and Shahnawaz are same age')
}

Question 6 :
How do you capture the result of a math equation like 42 * 38 in JavaScript? and show it in console.
              Method 1
                      console.log( 42*38 )
              Method 2
                      let x = 42, y=38
                      console.log( x*y )
              Method 3
                      let x = 42, y=38
                      let ans  = x*y
                      console.log( ans  )
            
Question 7 :
Write to program that ask user for his/her name age If name is Muzammil and age is 18 It should output "Muzammil has started programming" else if age is greater than 18 then it should output "Muzammil is a good programmer" otherwise it should output "Muzammil is newbie"
            let ageMuz = prompt('Enter the of Muzammil');

            if ( ageMuz == 18 ) {
                  console.log('Muzammil has started programming')
            } else if ( ageMuz > 18 ) {
                  console.log('Muzammil is a good programmer')
            } else {
              console.log('Muzammil is newbie')
            }
Question 8 :
If an employee works for 8 hours/day regularly and his rate per hour is 200 PKR. For every extra hour his rate per hour is 1.5 times more than regular hour. What will be his monthly (30 days) salary if he works 1 hour extra every day.
            workHours = prompt('Enter the number of hours employee worked/day');
            numberDays = prompt('Enter the number of days this month');

            let regualarHours = 8;
            let regularRate   = 200;
            
            regularRatePerDay   = regularHours * regularRate
            extraHourRatePerDay = (1.5 * regularRate) * ( workHours - regualarHours )

            salary = regularRatePerDay + extraHourRatePerDay;

            console.log(salary);
          
Question 9 :
Write a program to convert tempratures. User should provide inputs in Celcius and Farhanhiet and then outputs after converting C to F and F to C as below.
Fahrenhiet of provided celcius C(value) is : F(value)
Celcius of provided Fahrenhiet F(value) is : C(value)

   
          let cel = prompt('Enter the value in C');
          let far = prompt('Enter the value in F')

          newF    = cel * ( 9/5 ) + 32;
          newC    = ( 5/9 ) * ( far - 32 )
          
          console.log(`Fahrenhiet of provided celcius ${cel} is : F(${newF})`)
          console.log(`Celcius of provided Fahrenhiet ${far} is : F(${newC})`)  
          
Question 10 :
Create a variable "a" and assign it a value 15 Create another variable “b” and assign it a value 20 create a variable “formula” assign it the (a + b) whole square print out the value the above equation.
            let   a  =  15;
            let   b  =  20;

            formula  =  (a + b) ** 2
            
            console.log(formula);