function String_RansomNote() {
var fontList = new Array()
fontList[0] = "Arial, Helvetica, sans-serif"
fontList[1] = "Times New Roman, Times, serif"
fontList[2] = "Courier New, Courier, monospace"
fontList[3] = "comic sans ms, fantasy"
fontList[4] = "Zapf-Chancery, cursive"
// More fonts can be added by adding to this array
var rndFont, rndSize
var strLength = this.toString().length
var outStr = ""
var normal = false
for (var i = 0 ; i < strLength; i ++) {
// Generate a random font-family
rndFont = Math.round(Math.random() * (fontList.length-1))
// Generate a random font-size
rndSize = Math.round(Math.random() * 3) +2
if (rndSize>0) rndSize="+" + rndSize
// This randomizes sub and sup. Only add sub or sup if prior
// text is on the baseline. This keeps text more legible.
if (!normal)
rndPos = Math.round(Math.random() * 2)
else
rndPos = -1
outStr += "<FONT SIZE=\""+rndSize+"\" FACE=\"" + fontList[rndFont] + "\">"
normal = true
if (rndPos==0)
outStr+="<SUP>"
else
if (rndPos==1)
outStr+="<SUB>"
else
normal = false;
outStr += this.toString().substring(i,i+1)
if (rndPos==0)
outStr+="</SUP>"
else
if (rndPos==1)
outStr+="</SUB>"
outStr += "</FONT>"
}
// Return the modified string
return outStr
}
String.prototype.ransomNote = String_RansomNote
$(function() {
$("form").submit(function(e) {
e.preventDefault();
$(".out").html($("input[type=text]").val().ransomNote());
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.