JavaScript program to make text upside down - flip
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Turn text upside down. Rotate letters 180 degrees with Unicode.">
<meta name="author" content="Mohammad Towhidul Islam" />
<title>Flip Demo</title>
<style type="text/css">
textarea { font-family: "Arial Unicode MS", Batang }
h1 { margin-bottom: 2px;}
</style>
<script>
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}
function flipString(aString) {
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
var r = flipTable[c]
result[last - i] = r ? r : c
}
return result.join('')
}
var flipTable = {
a : 'u0250',
b : 'q',
c : 'u0254', //open o -- from pne
d : 'p',
e : 'u01DD',
f : 'u025F', //from pne
g : 'u0183',
h : 'u0265',
i : 'u0131', //from pne
j : 'u027E',
k : 'u029E',
//l : 'u0283',
m : 'u026F',
n : 'u',
r : 'u0279',
t : 'u0287',
v : 'u028C',
w : 'u028D',
y : 'u028E',
'.' : 'u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : 'u00BF', //from pne
'!' : 'u00A1',
"'" : ',',
'<' : '>',
'_' : 'u203E',
'u203F' : 'u2040',
'u2045' : 'u2046',
'u2234' : 'u2235',
'
' : '
'
}
for (i in flipTable) {
flipTable[flipTable[i]] = i
}
</script>
</head>
<body>
<h1>Flip Your Text</h1>
<form name="f">Original Text:
<br>
<textarea rows="5" cols="50" name="original" onkeyup="flip()"></textarea>
<br/>
<input value="Flip" onclick="flip()" type="button">
<br>
Flipped Text:
<br>
<textarea rows="5" cols="50" name="flipped"></textarea>
</form>
</body>
</html>
See demo here
Comments 5