Freamee Posted October 30, 2019 Posted October 30, 2019 Hello. i Would like to create a function like GetVehiclePrice(carname), and it gets the price from the array. Appreciate the help.
LeonMrBonnie Posted October 30, 2019 Posted October 30, 2019 (edited) 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 October 30, 2019 by LeonMrBonnie
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now