473,466 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why alert box doesn't show anything in it

13 New Member
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 ?

14 1774
gits
5,390 Recognized Expert Moderator Expert
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
bobyjones
13 New Member
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
5,390 Recognized Expert Moderator Expert
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
bobyjones
13 New Member
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
bobyjones
13 New Member
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
5,390 Recognized Expert Moderator Expert
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
bobyjones
13 New Member
@gits
yes (Just making this part to use the 10 characters)
Aug 2 '10 #8
gits
5,390 Recognized Expert Moderator Expert
??? 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
bobyjones
13 New Member
@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
5,390 Recognized Expert Moderator Expert
sure ... JavaScript handles variables case sensitive - have a look at the name of your variable and what you assign.
Aug 2 '10 #11
bobyjones
13 New Member
@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
5,390 Recognized Expert Moderator Expert
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
bobyjones
13 New Member
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
5,390 Recognized Expert Moderator Expert
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

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

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.