JavaScript Coding Tasks
You have at most 48 hours to complete the following challenges.
1. Optimus Prime... Number
The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.
Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs:
Level 1
whether the number is prime. If the number is not prime, then output all the numbers, from the list of the first 11 prime integers, which divide the number.
Level 2
all the numbers below the entered number that are prime numbers.
Level 3
all the numbers above the entered number (but only up to 1000) that are prime numbers.
2. TV and code
The screen size of a TV is given by the length of the rectangular diagonal. Traditional TVs come in 4:3 ratio, that is, the ratio of length to width is 4 to 3. This means, if the length is x
inches, then the width is (3/4)x
. LCD TVs come in 16:9 ratio.
Write a program that prompts the user to input the length of the diagonal (in inches) of the screen and allows the user to select which type of TV’s screen length, screen width, and screen area the user would like to calculate. Have the program display the desired results.
3. Hotel Booking Calculator
The cost of renting a room at a hotel is, say ₦8500 per night. For special occasions, such as a wedding or conference, the hotel offers a special discount as follows:
- If the number of rooms booked is at least 10, the discount is 10%; - at least 20, the discount is 20%;
- and at least 30, the discount is 30%. Also if rooms are booked for at least three days, then there is an additional 5% discount.
Write a program that prompts the user to enter the cost of renting one room, the number of rooms booked, the number of days the rooms are booked, and the sales tax (as a percent).
The program outputs the cost of renting one room, the discount on each room as a percent, the number of rooms booked, the number of days the rooms are booked, the total cost of the rooms, the sales tax, and the total billing amount. Your program must use appropriate named constants to store special values such as various discounts.
4. Manomi
Aliyu bought several acres of farm to grow and sell vegetables. Suppose that Aliyu wants to grow a maximum of two types of vegetables. Write a program that prompts Aliyu (or the user) to do the following:
- Enter the total farm area in acres.
- The number of vegetables (one or two) that the user wants to grow.
- If the user wants to grow two types of vegetables, then specify the portion, as a percentage, of the farm land used for each type of vegetable.
- Enter the seed cost, plantation cost, fertilizing cost, labor cost, for each acre.
- Enter vegetable selling price per acre.
Output the total revenue.
Output the profit/loss.
5. Tree Planting
Lex and Dauda want to plant evergreen trees along the back side of their yard. They do not want to have an excessive number of trees. Write a program that prompts the user to input the following:
- The length of the yard.
- The radius of a fully grown tree.
- The required space between fully grown trees.
The program outputs the number of trees that can be planted in the yard and the total space that will be occupied by the fully grown trees.
6. More Tree Planting
During each rainy season, Jelili and Omowunmi grow vegetables in their backyard and buy seeds and fertilizer from a local nursery. The nursery carries different types of vegetable fertilizers in various bag sizes.
When buying a particular fertilizer, they want to know the price of the fertilizer per pound and the cost of fertilizing per square foot.
Level 1
Write a program that prompts the user to enter the size of the fertilizer bag (in pounds), the cost of the bag (in naira), and the area (in square feet), that can be covered by the bag.
The program should output the desired result.
Level 2
Add another prompt for the user to also input their budget in naira. The program should now also output if the user's budget can cover the cost of gardening they want to undertake.
7. Record Breaking
Ra'ees has dreams of becoming an NBA star. He currently plays for his University basketball team.
A scouting firm has hired you to write a program that analyses the data of a player. In this case, they want to analyse Ra'ees stats.
Write a function that takes 3 parameters: points
,rebounds
, and assists
.
Each of these parameters is an array of integers.
The function should:
Level 1
- Finds out how many times the player achieved a new high record in either assists, rebounds or points and returns the values in an object like this:
{
points: 2,
rebounds: 3,
assists: 1
}
Level 2
- Finds out the games where the player achieved a new high record in either assists, rebounds or points and returns the values in an object like this:
{
points: [2,7],
rebounds: [3],
assists: [3,4,5]
}
Level 3
- Finds out how many times the player got a triple double and which games they got those
triple double
. Return the result in an object like this:{
count: 3,
games: [3,5,7]
}