Skip to content
Advertisement

How do I add a method so I can just a String instead of typing a whole statement

how do i make it so i only have to type “onion” instead of typing the whole thing. I am trying add a String for the Flavour of PackOfCrisps, but i have to type:

new PackOfCrisps(“onion”)

this is what i have done for the method

JavaScript

and this is the interface i get where i have to type: new PackOfCrisps(“onion”)

Advertisement

Answer

Create a method that takes a String as an input and creates a PackOfCrisps out of it. You can then have that method use your already existing method to insert this new PackOfCrisps object.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement