Skip to content

Instantly share code, notes, and snippets.

@nasirhm
Forked from sarahsga/practice-conditionals.md
Created June 10, 2018 19:39
Show Gist options
  • Save nasirhm/1c9096ed46cb3e06a553eabf0a2c13c7 to your computer and use it in GitHub Desktop.
Save nasirhm/1c9096ed46cb3e06a553eabf0a2c13c7 to your computer and use it in GitHub Desktop.

Q.1

The speed limit of Shahrah-e-Faisal is 60 km/hr. Write a program that, given a car's speed, tells whether it is Overspeeding or not.


Q.2

Your task is to develop a mini-facebook. If the user is logged in, it should print Welcome, <user's name>, otherwise it should print Please log in to continue!


Q.3

UIT wants you to write a program to tell if it is closed due to heat wave or not. If the temperature is greater than 40, it should print IMPORTANT ANNOUNCEMENT!!! UIT is closed tomorrow due to heat wave. Otherwise, it should do nothing.


Q.4

Write a program that tells if you are a millionaire or not. It is understood that a person who owns at least Rs. 1000000 is a millionaire.


Q.5

Tesla is a car-company that sells Electric cars. A variable isElectric tells if a car is electric or not. Write a program that prints The car has been manufactured by Tesla if it is electric.


Q.6

Your task is to develop the High Score feature in the game Colorless - A Memory Game. It should print:

  • Congratulations!! Your new high score is <user's high score> if the user's score is greater than the current high score

  • Try Again. You just need <the number of more points needed to beat the high score> to win! if the user's score is less than the current high score


Q.7

Write a program that prints This is EVEN if numb is even, and This is ODD if numb is odd.


Q.8

A year has 365 days. However, some years also have 366 days. A calendar year containing 366 days is called a leap year.

Write a program that prints This is a Leap year!!! if year is leap, and This is NOT a Leap year if the year is not leap.


Q.9

Ufone wants you to write a program that interacts with the caller when he attempts to make a call.

Each call costs Rs. 1 per minute. If the user has has less than Rs. 1 balance, the program prints Moazziz Sarif, aap ka mojooda balance iss call k lye naa kaafi hai. Please re-charge karain. If the user has Rs. 1 to 10, it prints Moazziz sarif, aap ka balance khatam honay wala hai and then prints Ring Ring!!. If the user has greater than Rs. 10 balance, the program prints Ring Ring only.


Q.10

TechKaro wants you to write a program that tells whether a student qualifies for the monthly awards or not. Students who have been absent 0, 1 or 2 times in a certain month are eligible for the award in that month. Otherwise they are not eligible.


Q.11

Hogwarts School of Witchcraft and Qizardry follows the folowing grading system for its Final Exams:

Total Marks = 100

Obtained Marks Grade
91 - 100 A+
86 - 90 A
80 - 85 A-
70 - 79 B
60 - 69 C
50 - 59 D
40 - 49 E
39 or less F

Create a program that prints the grade for a given value of Obtained Marks.

Q.12

An apple costs Rs. 10. A mango costs Rs. 15. A banana costs Rs. 8.

Ali has Rs. 100 only and wants to buy fruits for Fruit Chaat for Iftaar.

Write a program that:

  • Uses a variable noOfApples to store the number of apples Ali wants to buy.
  • Uses a variable noOfMangoes to store the number of mangoes Ali wants to buy.
  • Uses a variable noOfBananas to store the number of bananas Ali wants to buy.

The program should tell Ali if he has enough money to purchase the no. of fruits he wants. For example, it prints Shopping SUCCESS!! if he wants to buy 1 apple, 3 mango and 2 bananas (total cost = 1 * 10 + 3 * 15 + 2 * 8 = Rs. 71). But, it prints Shopping FAILED! Not enough money if he wants to buy 4 apples, 5 mangoes and 3 bananas (total cost = 4 * 10 + 5 * 15 + 3 * 8 = Rs. 139).


Q.13

Your task is to build a Customer Service Robot for TechKaro that is capable of answering frequently asked questions.

Cusomer Hi or Hello or Hey or Salam
Robot Thank you for calling TechKaro Customer Service. How may I help you?
---- ----
Customer Is UIT open today?
Robot Yes
---- ----
Customer What are the timings of today's class?
Robot 1:30 - 5:30
---- ----
Customer Where will the class be conducted?
Robot At CL-1, Usman Institute
---- ----

If the robot is asked anything else, the response will be: Sorry, I do not understand your question.


Q.14

Meezan Bank wants you to write a program which tells the customer if he/she has enough money in his/her account.

For example:

A customer has Rs. 10000 in his account.

If he asks the program to withdraw Rs. 500, the program would print Withdrawal SUCCESS! Your new balance is Rs. 9500

But, If he asks it to withdraw Rs. 15000, it would print Withdrawal FAILED! Sorry, you do not have sufficient balance.


Q.15

A hypothetical rocket can launch only if all of following weather conditions are met:

  • It is not raining
  • It is not snowing
  • The wind speed is less than 15 km/hr
  • It is not cloudy

Write a program that tells if the weather conditions are suitable for rocket launch or not.


Q.16

TechKaro admission test is designed to admit all students who meet at least one of the following criteria:

  • Has scored more than 10 points in Math test
  • Has scored more than 20 points in Computer test
  • Has scored more than 8 points in English test

Write a program that checks a student's marks and declares if he has passed the admission test or not.


Q.17

TechKaro admission test is designed to admit all students who meet all of the following criteria:

  • Has scored more than 10 points in Math test
  • Has scored more than 20 points in Computer test
  • Has scored more than 8 points in English test

Write a program that checks a student's marks and declares if he has passed the admission test or not.


Q.18

What will be the output of the following program:

let girls = 4;
let boys = 2;

if (girls > boys) {
    console.log('Girls are in majority');
} else if (girls < boys) {
    console.log('Boys are in majority');    
} else {
    console.log('The class has an equal number of girls and boys');        
}

Q.19

What will be the output of the following program:

let costOfApple = 10;
let costOfMango = 15;

if (costOfApple = costOfMango) {
    console.log('Apple and mango cost the same!');
} else if (costOfMango > costOfApple) {
    console.log("Mango is more expensive");
} else {
    console.log("Apple is more expensive");    
}

Q.20

What will be the output of the following program:

let maths = 100;
let english = 15;
let computerSkills = 60;

if (maths > 50 && english > 50 && computerSkills > 50) {
    console.log('Congratulations! You have passed the TechKaro Admission Test!');
} else if ((maths > 50 && english > 50) || computerSkills > 80) {
    console.log("You have also qualified!");
} else {
    console.log("Sorry! Please try again next year!");    
}

Q.21

What will be the output of the following program:

let maths = 100;
let english = 15;
let computerSkills = 60;

if (
    (maths > 50 && english > 50 && computerSkills > 50) || 
    (maths === 100 || english === 100 || computerSkills === 100)
) {
    console.log('Congratulations! You have passed the TechKaro Admission Test!');
} else if ((maths > 50 && english > 50) || computerSkills > 80) {
    console.log("You have also qualified!");
} else {
    console.log("Sorry! Please try again next year!");    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment