Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to write a program that can be saved in notepad as an .html, and the

ID: 3552625 • Letter: I

Question

I am trying to write a program that can be saved in notepad as an .html, and then be opened in a web-browser to display

the following:


Welcome to the Menu Maker!


Item name: Pastrami
Category: Sandwich
Price of item: 4.95

Item name: Ham
Category: Sandwich
Price of item: 5.25

Item name: Milk Shake
Category: Drink
Price of item: 2.95

Item name: Soft Drink
Category: Drink
Price of item: 1.49


Thank You!




However, the code I`m using for this, is not working. Can anyone help me find the error, or correct the javascript so it can open correctly?


<html>
<head>
<script type="text/javascript">


public class MenuItem {
        static String itemName;
        static String category;
        static double itemPrice;
    public static void main(String args[]) {
        System.out.println("Welcome to the Menu Maker!");
        System.out.println();
        MenuItem pastrami = new MenuItem("Pastrami", "Sandwich", 4.95);
        pastrami.displayInfo();
        System.out.println();
        MenuItem ham = new MenuItem("Ham", "Sandwich", 5.25);
        ham.displayInfo();
        System.out.println();
        MenuItem milkShake = new MenuItem("Milk Shake", "Drink", 2.95);
        milkShake.displayInfo();
        System.out.println();
        MenuItem softDrink = new MenuItem("Soft Drink", "Drink", 1.49);
        softDrink.displayInfo();
        System.out.println();
       
        System.out.println("Thank You!");
    }
    public MenuItem(String name, String catg, double price){
        itemName = name;
        category = catg;
        itemPrice = price;
    }
   
    public void displayInfo(){
        System.out.println("Item name: " + itemName);
        System.out.println("Category: " + category);
        System.out.println("Price of item: " + itemPrice);
    }
}


</script>
</body>
</html>

Explanation / Answer

<!-- The code you wrote was for java not javascript. -->

<!-- formatted code : https://gist.github.com/brijeshb42/9655017 -->


<html>

<head>

<script type="text/javascript">


function MenuItem(name,category,price){

this.itemName = name;

this.category = category;

this.price = price;

}


MenuItem.prototype.displayInfo = function(){

document.writeln("Item name: " + this.itemName + "<br />");

document.writeln("Category: " + this.category + "<br />");

document.writeln("Price of item: " + this.price + "<br />");

document.writeln('<br/>');

};


function main(){

document.writeln("Welcome to the Menu Maker!<br/>");

document.writeln('<br/>');

var pastrami = new MenuItem("Pastrami", "Sandwich", 4.95);

pastrami.displayInfo();

var ham = new MenuItem("Ham", "Sandwich", 5.25);

ham.displayInfo();

var milkShake = new MenuItem("Milk Shake", "Drink", 2.95);

milkShake.displayInfo();

var softDrink = new MenuItem("Soft Drink", "Drink", 1.49);

softDrink.displayInfo();

document.writeln('<br/>');

document.writeln('Thank You!');

}


main();


</script>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote