Sign in to follow this  
Freamee

get vehicle price from array

Recommended Posts

Hello.

 

i Would like to create a function like GetVehiclePrice(carname), and it gets the price from the array.

Appreciate the help.

Share this post


Link to post
Share on other sites
const CarPrices = {
    "zentorno": 5000,
    "turismor": 10000
};
function getVehiclePrice(carname)
{
    return CarPrices[carname|| null;
}

Just add the vehicles to the object like the example. The functions returns either the price of the vehicle, or null if the vehicle is not found.

Edited by LeonMrBonnie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.