Solved

Finding character position

Posted on 2011-03-15
14
288 Views
Last Modified: 2012-05-11
Hello,

i trying to make the following ,  the java code is asking for the name and a number,
what the number should show the character in that position for example i give the name : persia and the number 3
it should give

PERSIA
R

i did the uppercase part but im stuck at the second part Please help


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		
		number = parseInt (prompt("give a number"));
		
        </script>
		
		
		
	</body>
	

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

Open in new window

0
Comment
Question by:kensy11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136234
you need to use the charAt() method

http://www.w3schools.com/jsref/jsref_charat.asp

alert(name.charAt(2));
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35136238
alert(name.charAt(number));
0
 

Author Comment

by:kensy11
ID: 35136254
i already did it but not working

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />
		
		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );
		number = parseInt (prompt("give a number"));
		document.write(" character is: " + number + "<br />");
        </script>
	</body>
</html>
</body>
</html>

Open in new window

0
Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35136257
alert(name.charAt(number).toUpperCase());
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136277
This looks like works:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));

        </script>



	</body>


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

Open in new window

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136284
replace line 16 with

document.write(" character is: " + name.charAt(number) + "<br />");
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136289
sorry it should be


document.write(" character is: " + name.charAt(number-1) + "<br />");
0
 

Author Comment

by:kensy11
ID: 35136292
aah thanks, i got it now
one other question how can i count the whole text ten
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35136301
if you want to count the length of the text, then use name.length

http://www.w3schools.com/jsref/jsref_length_string.asp
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136321
This prints the length of the string

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.charAt(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


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

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136355
thanks again sorry one other question
 
for example i give the name persia and the number is 2

how can i write the name form the 2 position , in this case i shuld look like  RSIA

thanks again
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35136368
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number-1));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


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

Open in new window

0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 250 total points
ID: 35136379
counting form zero:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>11</title>
</head>
<body>
	<img src=image/MyNameIs.jpg />
	<br />


		<script type="text/javascript">
		name = prompt("your last name");
		name = name.toUpperCase();
		document.write( "Welkom " + name );



		number = parseInt (prompt("give a number"));
		document.write("<br>");
		document.write(name.substring(number));
	document.write("<br>");

	document.write(name.length);

        </script>



	</body>


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

Open in new window

0
 

Author Comment

by:kensy11
ID: 35136383
Thank you all
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
This video teaches viewers about errors in exception handling.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question