Question: class NerfGun { // Constructor takes one argument: the total number of projectiles supported by the instance // New instances initialize fully loaded and with
class NerfGun { // Constructor takes one argument: the total number of projectiles supported by the instance // New instances initialize fully loaded and with the safety on // Instances have a `shoot` method that takes no arguments: // * If there is ammo left and safety is off, method consumes one projectile and returns the string "Bang!" // * Shooting on empty or with the safety on, returns the string "Click!" // Instances have a `reload` method that takes a number and tops up the instance by that number // * Reloading returns a string in the following format: " projectiles left!" // * Reloading by more than capacity fills the instance to capacity // * Passing an argument which is not a number larger than zero returns the string "Error reloading!" // Instances have a `toggleSafety` method that takes no arguments and switches the state of the safety // * When engaging the safety, return "Safety enabled!" // * When disengaging the safety, return "Safety disabled!" // HINT: instances need to keep track of their maximum capacity as well as their current capacity } JavaScript
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
