Can someone tell me how to do multiple functions

One of my coding projects was to make a function where you told the computer how many metro rides you took and it would tell you whether to buy the monthly or the pay per ride metro card.

Before you read more heres the codepen link:https://codepen.io/coderkoji/pen/QWdVKaW

It would look something like this:

With 10 rides

You should purchase a pay per ride MetroCard! Your savings will be 99.50

That works fine when I try to run the function once but when I try to run it twice it doesnt work because the variable becomes a problem.

In order for the computer to know how many rides you took in this sentence:With 10 rides, I store it in a variable.

The directions for my coding class is: 1. Use PrintScreen() to print the messages returned from function 2 for 30 rides, 45 rides, 60 rides, and a user-inputted custom number of rides!

The problem is that If i do printToScreen(metrocard2(20)) it wont do the sentence With numOfRides rides right. Can someone tell me if theres a way to do this without a variable or some other way that can work please

Please I really dont know what to do

function foo(var){
  return (var*2)
}

It can be called like that foo(3) and will return 6
OR

let num = 4
let secondNumber = 10
let thirdNumber = 100
foo(num) //will return 8
foo(secondNumber) //20
foo(thirdNumber) //200

Can you please explain it more because I dont understand what you mean

Is there a reason you need rideNumber in the outer scope? If I call printToScreen(metrocard2(20)) the 20 in this case is how many rides you are saying you have correct? If I instantiate rideNumber to be equal to the value of savings then calling and running:

printToScreen(metrocard2(20))

printToScreen(metrocard2(10))

outputs:

With 20 rides
You should purchase a monthly MetroCard! Your savings will be 72.00

With 10 rides
You should purchase a monthly MetroCard! Your savings will be 99.50
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.