Forum Discussion
Ensuring a Random Number is not Re-picked
You could just use 2 arrays, one with the possible characters and one with the target character. Next, convert your name into an array, find matching values in the first array, and replace them with the corresponding value from the 2nd array. Something like the following:
var str = "Hello WOrld!"; //Replace with your StoryLine name variable.
str = str.toUpperCase();
var n = str.length;
var base = ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M','1','2','3','4','5','6','7','8','9','0','!','*','-',' ',];
var target = ['B','N','M','1','2','3','4','5','6','7','8','9','0','!','*','-','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V',' ',];
str = str.split("");
for (var i = 0; i < n; i++) {
for (var ii = 0; ii<40; ii++) {
if(str[i] == base[ii]){
str[i] = target[ii];
}
}
};
str = str.join('');
console.log(str); //Send this back to StoryLine or to your score board
If you run this in your browser console, it should return 'VPEEH OHAEZX'
If you replace Hello WOrld! with Owen Holt and run it again, you will get HOPO VHES
- k1967hHayes6 years agoCommunity Member
Brilliant
I need to play with this using the JavaScript trigger and see how far
I get it to workSent from my iPhone
- k1967hHayes6 years agoCommunity Member
What additional code do I need to save the resultant string into a VAR I can then store in Storyline?