By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Why alert box doesn't show anything in it

P: 13
I am making a JS scipt but it gets to the alert box and doesn't show anything in it here it is
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script Language="JavaScript" text="text/JavaScript">
  4.  
  5. var Stick = "27";
  6. var Coal = "78";
  7. var Torch = "105";
  8. var RedStone = "26";
  9. var RedstoneTorch = "53";
  10. var Stonetwo = "38";
  11. var sword = "65";
  12. var Stonethree = "101";
  13. var Pickaxe = "128";
  14. var Stoneone = "1";
  15. var Lever = "28";
  16.  
  17. var concatString;
  18.  
  19.  
  20. var Space1 = prompt ("enter item Name here","");
  21. var space2 = prompt ("enter second item  name here","");
  22.  
  23. concatString = "" + "";
  24.  
  25. alert(concatString)
  26.  
  27. </script>
  28.  
  29. </body>
  30.  
  31. </html>
  32.  
  33.  
  34.  
Jul 30 '10 #1

✓ answered by gits

it shows you exactly this:

Expand|Select|Wrap|Line Numbers
  1. concatString = "" + ""
which will be an empty string of course ... i guess you wanted to concat Space1 and space2 ?

Share this Question
Share on Google+
14 Replies


gits
Expert Mod 5K+
P: 5,377
it shows you exactly this:

Expand|Select|Wrap|Line Numbers
  1. concatString = "" + ""
which will be an empty string of course ... i guess you wanted to concat Space1 and space2 ?
Jul 30 '10 #2

P: 13
What I want to do Is add the Two variables numbers then say the variable name in wich the two variables add up to so say

Stick is 27
and coal is 78 then they add up to 105
and it shows 105's name torch
Aug 1 '10 #3

gits
Expert Mod 5K+
P: 5,377
for your original prompt-issue you might use:
Expand|Select|Wrap|Line Numbers
  1. concatString = parseInt(Space1) + parseInt(space2);
when you want to add numbers - otherwise it would concat the input as string ... for the lookup of the name you should already have an idea?
Aug 1 '10 #4

P: 13
No not realy but I have just started I am bound to find out something but if you can help that would be realy nice Thanks
Aug 1 '10 #5

P: 13
Okay so I just tried that and now it doesn't show the alert box at all! I realy don't know what caused that but I probably will find out.
Aug 1 '10 #6

gits
Expert Mod 5K+
P: 5,377
when using the mentioned parseInt() method a number must be typed into the prompt ... as i understood your answer before that hint?
Aug 1 '10 #7

P: 13
@gits
yes (Just making this part to use the 10 characters)
Aug 2 '10 #8

gits
Expert Mod 5K+
P: 5,377
??? what does not work - when you type in numbers then it will alert the sum of the typed numbers, doesn't it?
Aug 2 '10 #9

P: 13
@gits
Well I have made some changes and now it say undefined here is the script

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script Language="JavaScript" text="text/JavaScript">
  4.  
  5. var Stick = "27";
  6. var Coal = "78";
  7. var Torch = "105";
  8. var RedStone = "26";
  9. var RedstoneTorch = "53";
  10. var Stonetwo = "38";
  11. var sword = "65";
  12. var Stonethree = "101";
  13. var Pickaxe = "128";
  14. var Stone = "1";
  15. var Lever = "28";
  16.  
  17. var ConcatString;
  18.  
  19.  
  20. var Space1 = prompt ("enter item Name here","");
  21. var space2 = prompt ("enter second item  name here","");
  22.  
  23. concatString = parseInt(Space1) + parseInt(space2);
  24.  
  25. alert(ConcatString)
  26.  
  27.  
  28. </script>
  29.  
  30. </body>
  31.  
  32. </html>
Aug 2 '10 #10

gits
Expert Mod 5K+
P: 5,377
sure ... JavaScript handles variables case sensitive - have a look at the name of your variable and what you assign.
Aug 2 '10 #11

P: 13
@gits
I have checked all of that but it still says undefined...


have I told you you are realy helpful though
Aug 2 '10 #12

gits
Expert Mod 5K+
P: 5,377
Expand|Select|Wrap|Line Numbers
  1. concatString = parseInt(Space1) + parseInt(space2);
have a look at this line. you named the variable:
Expand|Select|Wrap|Line Numbers
  1. var ConcatString;
so the first letter differs.
Aug 2 '10 #13

P: 13
Thank you that works

and just one more favour Is it possible to make the number a word instead

like
27 + 78 = 105

could I change the 105 to "torch" for example?
Aug 2 '10 #14

gits
Expert Mod 5K+
P: 5,377
why not - create a lookup map (bascially a JavaScript object with some properties) like the following:

Expand|Select|Wrap|Line Numbers
  1. var lookupMap = {
  2.     'foo': 'bar',
  3.     'bar': 'foobar'
  4. };
  5.  
now you could simply refer to, lets say foo in the map as:
Expand|Select|Wrap|Line Numbers
  1. alert(lookupMap['foo']);
or even:
Expand|Select|Wrap|Line Numbers
  1. alert(lookupMap.foo);
Aug 3 '10 #15

Post your reply

Sign in to post your reply or Sign up for a free account.