Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var greetingString = "ITEM NAME:";
var myName = prompt ("ENTER ITEM NAME", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var greetingString = "QUANTITY:";
var myName1 = prompt ("ENTER QUANTITY", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var greetingString = "PRICE:";
var myName2 = prompt ("ENTER ITEM PRICE", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var myName1 = ("ENTER QUANTITY");
var myName2 = ("ENTER ITEM PRICE");
alert (myName1 * myName2)


What I have tried:

<HTML>
<BODY>
<SCRIPT LANGUAGE = JavaScript>

var greetingString = "ITEM NAME:";
var myName = prompt ("ENTER ITEM NAME", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var greetingString = "QUANTITY:";
var myName1 = prompt ("ENTER QUANTITY", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var greetingString = "PRICE:";
var myName2 = prompt ("ENTER ITEM PRICE", "");
var concatString;
document.write(greetingString + " " + myName + "<BR>");

var myName1 = ("ENTER QUANTITY");
var myName2 = ("ENTER ITEM PRICE");
alert (myName1 * myName2)

</SCRIPT>
</BODY>
</HTML>
Posted
Updated 14-Feb-23 2:54am
v2
Comments
[no name] 11-Feb-23 13:21pm    
You also keep using "myName" everywhere when you shouldn't (by just copying and pasting).

1 solution

Oh boy, where to begin...

First, your variable names are bad. They should be named to reflect the values they hold. For example, you're prompting for a quantity, but the variable you're assigning that quantity to is called "myName1". Not good.

You've got a variable called concatString that isn't used anywhere, and you define it 3 times. You're use of greetingString can just be removed as it serves no real purpose.

Next, look at the last 3 lines of the script. You're replacing the values of myName1 and myName2 with strings, overwriting the values they were assigned by the prompts.

Finally, what is the result of multiplying to strings together? "ENTER QUANITIY" x "ENTER ITEM PRICE" does not make any sense to humans, let alone the interpreter. Those two lines can be removed entirely as they are useless.

The code you posted reflects no thought about the code, but a "copy'n'paste off the web and pray it works" mentality.

You really need to go back to the basics in your class or the book you're using to learn this. Trying to learn this off of YouTube videos or some coding challenge site is not going to work.

The only other hint I'll give you is your script can be rewritten into 7 lines of code.

Oh! And the script tab should read (note the quotes):
HTML
<script language="javascript">
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900