Compteur :
| Solution d'exercice - JavaScriptExercice JavaScript 15 :<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Page de test pour JavaScript</title>
</head>
<body>
<h1>Page de test pour JavaScript</h1>
<script language="javascript" type="text/javascript">
<!--
function rot13(msg)
{
var a = new String("a")
var aCharCode = a.charCodeAt()
var z = new String("z")
var A = new String("A")
var ACharCode = A.charCodeAt()
var Z = new String("Z")
var transformed = new String()
var currentCharCode
var index = -1
while(++index < msg.length)
{
currentCharCode = msg.charCodeAt(index)
if(currentCharCode >= aCharCode && currentCharCode <= z.charCodeAt())
transformed += String.fromCharCode(((currentCharCode - aCharCode + 13) % 26) + aCharCode)
else if(currentCharCode >= ACharCode && currentCharCode <= Z.charCodeAt())
transformed += String.fromCharCode(((currentCharCode - ACharCode + 13) % 26) + ACharCode)
else
transformed += msg.charAt(index)
}
return transformed
}
document.writeln("<form name=\"myForm\">")
document.writeln("<table align=\"center\">")
document.writeln("<tr><td bgcolor=\"#f1f1d1\">")
document.writeln("Texte source :<br><textarea rows=\"5\" cols=\"60\" name=\"source\"></textarea>")
document.writeln("</td></tr>")
document.writeln("<tr><td bgcolor=\"#f1d1f1\">")
document.writeln("Texte transformé :<br><textarea rows=\"5\" cols=\"60\" name=\"destination\"></textarea>")
document.writeln("</td></tr>")
document.writeln("<tr><td align=\"center\"><button onclick=\"document.myForm.destination.value=rot13(document.myForm.source.value);return false;\">Transformation</button></td></tr>")
document.writeln("</table>")
document.writeln("</form>")
//-->
</script>
<noscript>
<p align="justify"><font color="red"><b>L'affichage de cette page nécessite l'activation du JavaScript.</b></font></p>
</noscript>
</body>
</html>
Pour voir le résultat, cliquez -> ici <-. |
|
Ce site est optimisé pour Mozilla FireFox. L'affichage n'est pas garanti pour votre navigateur. Pour plus d'informations, cliquez -> ici <-.
© Sébastien Adam 1996 ~ 2010 - http://www.sebastienadam.be/ - Le contenu de ce site est soumis à licence. Gestionnaire du site