We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Javascript anyone?; A little help here people!?
Topic Started: Jan 27 2007, 06:05 PM (676 Views)
Lulubrfc
Member
[ * ]
Quote:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Code Practise</title>
<SCRIPT LANGUAGE="javascript">
number=prompt("Please enter the four digit number?");
alert("The Number You Entered is: "+number);
number.charAt(0)
number.charAt(1)
number.charAt(2)
number.charAt(3)

document.write("The Code is:")

document.write(number.charAt(2))
document.write(number.charAt(3))
document.write(number.charAt(0))
document.write(number.charAt(1))


</SCRIPT>
</head>

<body>
</body>
</html>


I really need a method of gaining the 4 digit code code, then adding 10 to each of the digits, then displaying in a different order (as completed)...does anyone know how to do that?? Or point me in a direction that would help?
Thanks!

x x
Offline Profile Quote Post Goto Top
 
DeltaOne
House Lucius {gone forever}
[ *  *  *  * ]
You wouldn't believe this, but my sister had to do something like it as her homework for school :lol: (something easier, but along the same lines, although she had to do it in c++)



*I'll think over a bit and if I can help you I'll edit this post, if not, others may help you more than me*
Offline Profile Quote Post Goto Top
 
Lulubrfc
Member
[ * ]
Thanks in advance..I've been trying all night.:)

x
Offline Profile Quote Post Goto Top
 
DeltaOne
House Lucius {gone forever}
[ *  *  *  * ]
Here's some C++ combined with javascript, just so you get the hang of it. Feel free to use whatever you want from the below, it's just a draft with alot of code written that will surely point you in the right direction.
(I hope the code is self-explanatory)

Code:
 

<head>
<title>test</title>
</head>
<body>
<SCRIPT LANGUAGE="javascript">
n=prompt("Please enter the four digit number?");
i=1;
m=n;
d1=10;
d2=10;
d3=10;
d4=10;

if ((n.length >=5 || n.length <=3)  || (isNaN(n) == true))
{alert("Only 4 digit numbers, please")}
else
{

while(i<=4)
{
n=m%10;
m=parseInt(m/10);
if (i==1)
{
d4=d4+n;
}
else
{
if (i==2)
{
d3=d3+n;
}
 else
 {
  if (i==3)
  {
  d2=d2+n;
  }
   else
   {
   if (i==4)
   {
   d1=d1+n;
   }
   }
 }
}
i=i+1;
}

document.write("<br>" + d2 + " <- the 2nd digit of the number with 10 added is this one<br>")
document.write("<br>" + d4 + " <- the 4th digit of the number with 10 added is this one<br>")
document.write("<br>" + d1 + " <- the 1st digit of the number with 10 added is this one<br>")
document.write("<br>" + d3 + " <- the 3rd digit of the number with 10 added is this one<br>")
}
</script>
</body>
</html>
Offline Profile Quote Post Goto Top
 
Lulubrfc
Member
[ * ]
Thanks..I can see where I went completely wrong! :-/


Offline Profile Quote Post Goto Top
 
DeltaOne
House Lucius {gone forever}
[ *  *  *  * ]
What was it?

Glad to be of service anyway :)
Offline Profile Quote Post Goto Top
 
xtrackterx
Member Avatar
Member
[ *  *  * ]
Javascript is easy.
Offline Profile Quote Post Goto Top
 
Larksmann
Member Avatar
5 Meters Up and Inverted
[ *  *  * ]
xtrackterx
January 27, 2007 08:33 PM
Javascript is easy.

I'm sure your input is greatly appreciated.
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
A much shorter way:

Code:
 
<script>
num=prompt("Enter 4-digit number below:","");
one=num.charAt(2)*1+10;
two=num.charAt(3)*1+10;
three=num.charAt(0)*1+10;
four=num.charAt(1)*1+10;
document.write(one+" "+two+" "+three+" "+four);
</script>


-IMP ;) :)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply