Conditional (If-Else) Statements – Exercises
Quiz Summary
0 of 17 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 17 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
-
Unfortunately, your results in the simulator were not up to the desired standards. 😔
However, take advantage of your unlimited access and continue to practice.
Remember, persistence and dedication will lead to mastery. 😎 -
Congratulations! 🎉
You have successfully passed the simulator and are now one step closer to achieving your certification.
We hope you will consider joining us again in your future certification journey.Wishing you the best of luck with the upcoming exam. Keep up the great work! 💪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 17
1. Question
In an e-commerce application, you want to check if a user is eligible for free shipping based on their order total. If the
orderTotalis 50 or more, set theeligibleForFreeShippingvariable totrue. Otherwise, set it tofalse.-
Decimal orderTotal = 55.00;
Boolean eligibleForFreeShipping;
if (orderTotal >= 50){
eligibleForFreeShipping = ;
} else {
eligibleForFreeShipping = ;
}
CorrectIncorrect -
-
Question 2 of 17
2. Question
In your Salesforce instance, you’re working on logic that changes the
Statusof aCaserecord based on itsPriority. If thePriorityis'High', theStatusshould be set to'Urgent'; otherwise, it should be'Normal'.Complete the following Apex snippet:
-
Case c = new Case(Priority = ‘High’);
if ( )
c.Status = ‘Urgent’;
else
c.Status = ‘Normal’;
System.assert(c.Status == ‘Urgent’);
CorrectIncorrect -
-
Question 3 of 17
3. Question
A Salesforce system manages warranties for sold items. The warranty duration in months depends on the product
priceand itscategory. Products in the “electronics” category with a price above $500 get a 24-month warranty. Other “electronics” get a 12-month warranty. All other categories get a 6-month warranty regardless of price.Complete the blank spaces:
-
if ( && ) {
warrantyMonths = 24;
} else if ( ) {
warrantyMonths = 12;
} else {
warrantyMonths = 6;
}
CorrectIncorrect -
-
Question 4 of 17
4. Question
In a Salesforce application, we want to categorize contacts based on their
ageandisStudentstatus to provide targeted marketing messages. Contacts who are students and under 25 years old get a message for student discounts. Those who are 25 years and older, whether students or not, get a different message. All other contacts receive a general message.Complete the blank spaces to correctly implement this logic:
-
if ( && ) {
marketingMessage = ‘Check out our special student discounts!’;
} else if ( ) {
marketingMessage = ‘You might be interested in our premium offers!’;
} else {
marketingMessage = ‘Explore our new collection!’;
}
CorrectIncorrect -
-
Question 5 of 17
5. Question
You are creating a user management system. Based on user feedback, they should be classified into three categories:
1. Happy: if feedback score is 8 or above.
2. Neutral: if feedback score is between 5 (inclusive) and 8.
3. Unhappy: if feedback score is less than 5.Complete the provided Apex code:
-
Integer feedbackScore = 7;
String userFeedback;(feedbackScore >= 8) {
userFeedback = ‘Happy’;
} (feedbackScore >= 5 && < 8) {
userFeedback = ‘Neutral’;
} {
userFeedback = ‘Unhappy’;
}
CorrectIncorrect -
-
Question 6 of 17
6. Question
Suppose you’re developing an inventory management system. You have two variables,
productStockto represent the number of a specific item in stock andorderQuantityto represent the quantity of the item a customer wants to order. Fill in the blanks to classify the order status based on the stock and order quantity:1. Available: if the
orderQuantityis less than or equal toproductStock.
2. Limited Stock: if theorderQuantityis more thanproductStockbutproductStockis greater than 0.
3. Out of Stock: ifproductStockis 0.-
Integer productStock = 20;
Integer orderQuantity = 15;
String orderStatus;(orderQuantity <= productStock) {
orderStatus = ‘Available’;
} ( > 0) {
orderStatus = ‘Limited Stock’;
} {
orderStatus = ‘Out of Stock’;
}
CorrectIncorrect -
-
Question 7 of 17
7. Question
Given a Salesforce Apex variable named
temperature, fill in the blanks to classify the weather based on the temperature value:1. Cold: if temperature is less than or equal to 10.
2. Moderate: if temperature is greater than 10 and less than 25.
3. Hot: if temperature is greater than or equal to 25.-
Integer temperature = 18;
String weatherCondition;(temperature <= 10) {
weatherCondition = ‘Cold’;
} (temperature < 25) {
weatherCondition = ‘Moderate’;
} {
weatherCondition = ‘Hot’;
}
CorrectIncorrect -
-
Question 8 of 17
8. Question
You are given a Salesforce Apex code snippet with two variables:
priceanddiscountType. The value ofpricerepresents the cost of an item, anddiscountTypesignifies the type of discount that can be applied to the product. The discount types are as follows:1. No discount
2. 10% discount
3. 20% discountYour task is to complete the conditional statement to apply the right discount to the price.
-
Decimal price = 100.00;
Integer discountType;
Decimal discountedPrice;
(discountType == 0) {
discountedPrice = price;
} (discountType == 1) {
discountedPrice = price * 0.90;
} {
discountedPrice = price * 0.80;
}
CorrectIncorrect -
-
Question 9 of 17
9. Question
A Salesforce application categorizes products based on their
averageRatingandnumberOfReviews. The categorizations are:1. Star Product: Items with an average rating of 4.5 and above and more than 50 reviews.
2. Popular Product: Items with an average rating between 4.0 and 4.5, regardless of the number of reviews.
3. New Arrival: Products with less than 10 reviews.
4. Average Product: All other products.Fill in the missing pieces:
-
Decimal averageRating;
Integer numberOfReviews;
String productCategory;
if ( && ) {
productCategory = ‘Star Product’;
} else if ( && ) {
productCategory = ‘Popular Product’;
} else if ( ) {
productCategory = ‘New Arrival’;
} else {
productCategory = ‘Average Product’;
}
CorrectIncorrect -
-
Question 10 of 17
10. Question
Imagine you are building an application in Salesforce that categorizes products based on both their
priceandsalesVolume(number of units sold). The classification is as follows:1. Premium: Products priced over $1000 or those that have sold more than 500 units.
2. Standard: Products priced between $500 and $1000, or those that have sold between 250 and 500 units.
3. Basic: All other products.Fill in the blank spaces to correctly classify the products:
-
Decimal price;
Integer salesVolume;
String productClassification;if ( || ) {
productClassification = ‘Premium’;
} else if (( && ) || ( && )) {
productClassification = ‘Standard’;
} else {
productClassification = ‘Basic’;
}
CorrectIncorrect -
-
Question 11 of 17
11. Question
A Salesforce application is designed to categorize customer feedback based on satisfaction levels. The levels are:
1. Highly Satisfied: “Excellent”
2. Moderately Satisfied: “Good”
3. Neutral: “Average”
4. Unsatisfied: “Poor”Complete the code below based on the
satisfactionScoreto assign the correct feedback category:-
Integer satisfactionScore;
String feedbackCategory;
if ( ) {
feedbackCategory = ‘Excellent’;
} else if ( ) {
feedbackCategory = ‘Good’;
} else if ( ) {
feedbackCategory = ‘Average’;
} else {
feedbackCategory = ‘Poor’;
}
CorrectIncorrect -
-
Question 12 of 17
12. Question
You are creating a simple grading system in Salesforce Apex. The grade is determined based on a student’s score. The grading is as follows:
1. Score 90 and above: ‘A’
2. Score 80 to 89: ‘B’
3. Score 70 to 79: ‘C’
4. Score below 70: ‘F’Complete the missing parts of the code to implement this grading system:
-
Integer score;
String grade;if ( ) {
grade = ‘A’;
} else if ( ) {
grade = ‘B’;
} else if ( ) {
grade = ‘C’;
} else {
grade = ‘F’;
}
CorrectIncorrect -
-
Question 13 of 17
13. Question
In an application that manages online courses, there’s a system that assigns a status to a student based on their
percentageCompletion:1. If the completion is 100%, the status is ‘Completed’.
2. If the completion is between 80% and 99%, the status is ‘Almost Completed’.
3. If the completion is between 50% and 79%, it’s ‘Halfway There’.
4. If the completion is below 50%, it’s ‘Just Started’.
5. Any other values (above 100% or negative) should be ‘Invalid Percentage’.Fill in the missing pieces:
-
Decimal percentageCompletion;
String courseStatus;if ( ) {
courseStatus = ‘Completed’;
} else if ( && ) {
courseStatus = ‘Almost Completed’;
} else if ( && ) {
courseStatus = ‘Halfway There’;
} else if ( ) {
courseStatus = ‘Just Started’;
} else {
courseStatus = ‘Invalid Percentage’;
}
CorrectIncorrect -
-
Question 14 of 17
14. Question
In a Salesforce application, a field captures the
hoursWorkedby an employee in a week. Based on the hours, the application determines the status of the employee:1. If they worked 40 hours, they are labeled ‘Full-Time’.
2. If they worked between 20 and 39 hours, they are ‘Part-Time’.
3. If they worked less than 20 hours but more than 0, they’re ‘Freelancer’.
4. If no hours are recorded or it’s negative, the status is ‘Invalid Entry’.Fill in the blanks:
-
Integer hoursWorked;
String employmentStatus;if ( ) {
employmentStatus = ‘Full-Time’;
} else if ( && ) {
employmentStatus = ‘Part-Time’;
} else if ( && ) {
employmentStatus = ‘Freelancer’;
} else {
employmentStatus = ‘Invalid Entry’;
}
CorrectIncorrect -
-
Question 15 of 17
15. Question
In a Salesforce application, there’s a system that determines the type of notification a user receives based on their
accountAgein months and thenumberTransactionsthey’ve completed:1. Users with an account age less than 6 months and more than 50 transactions receive a ‘Highly Active Newbie’ badge.
2. Users with an account age between 6 to 12 months or more than 100 transactions receive a ‘Rising Star’ badge.
3. Users with an account age of more than 24 months and fewer than 50 transactions are tagged ‘Loyal Customer’.
4. All other users receive a ‘Regular’ badge.Fill in the blanks:
-
Integer accountAge;
Integer numberTransactions;
String userBadge;if ( && ) {
userBadge = ‘Highly Active Newbie’;
} else if ( && || ) {
userBadge = ‘Rising Star’;
} else if ( && ) {
userBadge = ‘Loyal Customer’;
} else {
userBadge = ‘Regular’;
}
CorrectIncorrect -
-
Question 16 of 17
16. Question
In a Salesforce application that monitors server uptime, there are different levels of notifications based on
serverUptimepercentage and thenumberOfUserson that server:
1. If server uptime is below 90% and users are more than 1000, raise a ‘Critical Alert’.
2. If server uptime is between 90% and 95% or users are between 500 to 1000, raise a ‘Warning Alert’.
3. For any other cases, log a ‘Normal Status’.Fill in the missing pieces:
-
Decimal serverUptime;
Integer numberOfUsers;
String alertLevel;if ( && ) {
alertLevel = ‘Critical Alert’;
} else if ( || ) {
alertLevel = ‘Warning Alert’;
} else {
alertLevel = ‘Normal Status’;
}
CorrectIncorrect -
-
Question 17 of 17
17. Question
In a Salesforce application, there’s a need to provide discounts to customers based on their
purchaseAmountand theirmembershipDurationin years. The rules for discount are:1. Customers with a purchase amount greater than $500 and membership duration of 5 years and above get a 20% discount.
2. Customers with a purchase amount between $200 and $500 or a membership duration of 3 to 5 years get a 10% discount.
3. Customers with a purchase amount below $200 and membership duration less than 3 years get no discount.Fill in the blanks:
-
Decimal purchaseAmount;
Integer membershipDuration;
Decimal discountPercentage;if (purchaseAmount 500} && membershipDuration 5) {
discountPercentage = 20.0;
} else if ((purchaseAmount 200 && purchaseAmount 500) || membershipDuration 3 && membershipDuration ) {
discountPercentage = 10.0;
} else if (purchaseAmount 200 && membershipDuration 3) {
discountPercentage = 0.0;
}
CorrectIncorrect -