Skip to content

Instantly share code, notes, and snippets.

@Wanagram
Last active March 14, 2016 14:43
Show Gist options
  • Save Wanagram/4f0e4e976f5f6522f18b to your computer and use it in GitHub Desktop.
Save Wanagram/4f0e4e976f5f6522f18b to your computer and use it in GitHub Desktop.
palindrome
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
svg { width:100%; height: 100% }
</style>
</head>
<body>
<script>
var string = "chicken";
var palinArray = [];
var palinReverse = [];
var count = 0;
for(i=0;i<string.length;i++){
palinArray.push(string[i]);
}
for(i=palinArray.length-1;i>-1;i--){
palinReverse.push(palinArray[i])
}
for(i=0;i<palinReverse.length;i++){
if(palinReverse[i] != palinArray[i] ){
count++;
}
}
if(count == 0 && string.length!=0){
console.log("This is a palindrome!")
}
else if(string.length == 0){
console.log("You didn't type a word!")
}
else{
console.log("This is not a palindrome!")
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment