Created
September 19, 2015 15:07
-
-
Save kevincolten/e987f64496976b8acbb0 to your computer and use it in GitHub Desktop.
Pig Latin App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var prompt = require('prompt'); | |
prompt.start(); | |
prompt.get(['word'], function(err, result) { | |
var word = result['word']; | |
var vowelIndex = word.indexOf('a'); | |
if ( (word.indexOf('e') > -1 && word.indexOf('e') < vowelIndex) || (vowelIndex === -1) ) { | |
vowelIndex = word.indexOf('e'); | |
} | |
if ( (word.indexOf('i') > -1 && word.indexOf('i') < vowelIndex) || (vowelIndex === -1) ) { | |
vowelIndex = word.indexOf('i'); | |
} | |
if ( (word.indexOf('o') > -1 && word.indexOf('o') < vowelIndex) || (vowelIndex === -1) ) { | |
vowelIndex = word.indexOf('o'); | |
} | |
if ( (word.indexOf('u') > -1 && word.indexOf('u') < vowelIndex) || (vowelIndex === -1) ) { | |
vowelIndex = word.indexOf('u'); | |
} | |
var firstPart = word.slice(0, vowelIndex); | |
var restWord = word.slice(vowelIndex, word.length); | |
console.log('vowelIndex: ' + vowelIndex); | |
console.log('firstPart: ' + firstPart); | |
console.log('restWord: ' + restWord); | |
console.log('Pig Latin Word: ' + restWord + firstPart + 'ay'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment