Question

In: Computer Science

Complete this javascript question according to the instructions given in the comments. *** DO NOT CHANGE...

Complete this javascript question according to the instructions
given in the comments.

*** DO NOT CHANGE any of the code that you are not instructed to. */

////////////////////
// Hint: If you see a console.log() in my examples, it is
// likely a "return" goes there in your assignment.
///////////////////

// 1) Define a "Vehicle" class that has a "wheels" property equal to 4 in
// the constructor and a method named "rolling" that returns a string
// equal to "Rolling down the highway on {wheels value} wheels."
// Use the class to instantiate a new object named myRide.

// Define a "Car" subclass based on the parent class "Vehicle".
// The "Car" class should also accept a parameter "carDoors". The
// "Car" class should have a "doors" property that is set to the
// value of the "carDoors" parameter. Add a method named "doorsAndWheels"
// that returns a string equal to "My car has {doors value} doors and
// {wheels value} wheels."
// Use the "Car" class to instantiate a new object named myCruiser.

// Define a "Pie" class with the properties "flavor" and "slices".
// Set the "flavor" property equal to a parameter named "pieFlavor".
// Set the "slices" property equal to 8. Add a "getSlices" method
// and a "setSlices" method that function as expected.
// Use the "Pie" class to instantiate a new object named myDessert

// Define a Factory Function named "iceCreamFactory" that
// accepts a "iceCreamFlavor" parameter.
// The function will create an object that has a "flavor"
// property which is private. Set the "flavor" property
// value to the parameter "iceCreamFlavor" value.
// The function should also add a public "cone" property
// that has the value "waffle".
/////////////////////
// The factory function should add a method to the object
// it creates called "serve" that returns a string:
// "Here's your { flavor } ice cream in a { cone } cone."
///////////////////
// Hint: Look at this week's image for Factory Functions
////////
// Use iceCreamFactory to instantiate an object named myScoop.

// Using a literal (not a class or function), define an object
// named "webDev" that has the following key-value pairs:
// foundation: "html", design: "css", logic: "javascript",
// build: function(){return "building..."}
// Convert the "webDev" object to JSON, and save the converted
// data in a variable named sendJSON.
// Now convert the sendJSON data back to an object
// named receiveJSON.

Solutions

Expert Solution

Javascript:

class Vehicle {
  constructor(wheels) {
    this.wheels = new Number(wheels);
  }
  rolling() {
    return new String("Rolling down the highway on " + this.wheels + " wheels");
  }
}
let myRide = new Vehicle(4);
//document.write(myRide.rolling());
//console.log(myRide.rolling());

class Car extends Vehicle {
  constructor(carwheels, carDoors) {
    super(carwheels);
    this.carDoors = new Number(carDoors);
    
  }
  doorsAndWheels() {
    return new String("My car has " + this.carDoors + " and " + 
this.wheels +" wheels");
  }
}
let myCruiser = new Car(4,4);
//document.write(myCruiser.doorsAndWheels());
//console.log(myCruiser.doorsAndWheels());

class Pie {
    constructor(flavour, slices) {
    this.flavor = new String(flavour);
    this.slices = new Number(slices);
  }  
  setFlavor(flavor) {
    this.flavor = new String(flavor);
  }
  getFlavor() {
    return this.flavor;
  }
  setSlices(slices) {
    this.slices = new Number(slices);
  }  
  getSlices() {
    return this.slices;
  }
}
let myDessert = new Pie("pieFlavor",8);
myDessert.setFlavor("pieFlavor");
myDessert.setSlices(8);

class IceCream {
  cone = "waffle"
  constructor(flavour) {
        this.flavor = new String(flavour);
  }
  serve() {
    return new String("Here's your "+  this.flavor + " ice cream in a " + this.cone + " cone.");
  }
} 
function iceCreamFactory (iceCreamFlavor) {
        let myDessert = new IceCream(iceCreamFlavor);
        return myDessert;
};
Json Conversion

let webDev = {
 foundation: "html",
 design: "css", 
 logic: "javascript",
 build: function(){return "building..."}
}
let sendJSON = JSON.stringify(webDev);
let receiveJSON = JSON.parse(sendJSON);

Related Solutions

/* Complete this javascript file according to the individual instructions given in the comments. */ //...
/* Complete this javascript file according to the individual instructions given in the comments. */ // 1) Declare an array named myArray // Assign myArray three elements: 'Tuesday',3,true // Print myArray to the console with console.log() // 2) Use typeof on each element in myArray // Example: typeof myArray[0]; // Print all 3 lines to the console with console.log() // 3) Declare a variable named myStart and set it to // the value of the length property applied of myArray...
/* Assignment : Complete this javascript file according to the individual instructions given in the comments....
/* Assignment : Complete this javascript file according to the individual instructions given in the comments. */ // 1) Utilize comments to prevent the following line from executing alert('Danger!'); // 2) Assign a value of 5 to a variable named x // and print the value of x to the console // 3) Assign a value of 10 to a variable named myNum // and print the value of myNum to the console // 4) Assign the product of x...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1)...
/* Assignment: Complete this javascript file according to instructions given in the comments. */ // 1) Declare a variable named myName equal to your first name //Firstname is Susan // Construct a basic IF statement that prints the variable to the // console IF the length of myName is greater than 1 // 2) Copy your IF statement from above and paste it below // Change the IF statement to check if the length of myName // is greater than...
/* complete javascript file according to the individual instructions given in the comments. */ // 1)...
/* complete javascript file according to the individual instructions given in the comments. */ // 1) Prompt the user to enter their first name. // Display an alert with a personal greeting for the user // with their first name (example: Hello, Dave!) // 2) Create a Try code block that will cause a ReferenceError. // Create a Catch code block that will display the error in the // console with console.error() // 3) Prompt the user to enter a...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1)...
/* Complete this javascript file according to the individual instructions given in the comments. */ //1) Create an Object using an Object Literal (the easiest way) // Name your object Breakfast // Your object should have 3 key:value pairs // The three keys should be: breakfast, lunch, dinner // Put your food choice for each as the value // 2) Display the keys of your Breakfast object in the // console. We have learned two ways to do this.. either...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a...
/* Assignment : Complete this javascript file according instructions in comments. */ // 1) Create a for loop that loops through its code block 10 times // In the first statement, set the variable i equal to zero // In the second statement, tell the loop to execute while i is less than ten // In the third statement, increment i by one each time the loop executes // In the code block of the loop, print the variable i...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include...
Complete the program used on the instructions given in the comments: C++ lang #include <string> #include <vector> #include <iostream> #include <fstream> using namespace std; vector<float>GetTheVector(); void main() { vector<int> V; V = GetTheVector(); //reads some lost numbers from the file “data.txt" and places it in //the Vector V Vector<int>W = getAverageOfEveryTwo(V); int printTheNumberOfValues(W) //This should print the number of divisible values by 7 //but not divisible by 3. PrintIntoFile(W); //This prints the values of vector W into an output file...
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
I need to complete this C++ program. The instructions are in the comments inside the code...
I need to complete this C++ program. The instructions are in the comments inside the code below: ------------------------------------------------------------------------- Original string is: this is a secret! Encypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! //Encoding program //Pre-_____? //other necessary stuff here int main() { //create a string to encrypt using a char array cout<< "Original string is: "<<string<<endl; encrypt(string); cout<< "Encrypted string is: "<<string<<endl; decrypt(string); cout<<"Decrypted string is: "<<string<<endl; return 0; } void encrypt(char e[]) { //Write implementation...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a...
/* Complete the TO DO comments below */ window.onload = function() { /* TODO add a border to the header of the page (a) a simple type selector, and (b) the style property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the text of the h1 element by using (a) the first-child pseudo selector, and (b) the innerHTML property of the element object. */ document.querySelector('TODO').TODO = TODO; /* TODO change the background-color of the section with id...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT