45.6k views
5 votes
Write an if-else statement for the following: If user_tickets is less than 5, assign 1 to num_tickets. Else, assign user_tickets to num_tickets. Sample output with input: 3 Value of num_tickets: 1

User Denys
by
3.4k points

1 Answer

6 votes

Answer:

Please find the answer in the attached image.

Step-by-step explanation:

I wrote this program using JavaScript programming language.

// A function to check tickets

function tickets(user_tickets){

var num_tickets;

if (user_tickets < 5) {

num_tickets = 1;

return ('num_tickets: '+ num_tickets);

}

else {

num_tickets = user_tickets;

return('num_tickets: '+ num_tickets);

}

}

// Testing the tickets function

// With user_tickets = 3, 5, 8, and 1

console.log(tickets(3));

console.log(tickets(5));

console.log(tickets(8));

console.log(tickets(1));

Write an if-else statement for the following: If user_tickets is less than 5, assign-example-1
User VINOTH ENERGETIC
by
4.1k points