Published
Edited
Mar 13, 2019
Importers
Insert cell
Insert cell
CreatePigLatinPhrase('the quick brown fox jumped over the lazy dog')
Insert cell
function CreatePigLatinPhrase(sentence) {
const pigLatinSentence = []; // This is an array to carry the words in the sentence.
const words = splitSentenceIntoWords(sentence); // This function puts the sentence into an array of words
words.forEach((word) => { // Loops over each word

const wordType = checkWhatWordItIs(word.toLowerCase()); // Checks what the word is
const wordInPigLatin = convertWordToPigLatin(wordType, word.toLowerCase()); // Converts the word to pig latin
pigLatinSentence.push(wordInPigLatin); // Adds the word to the pig latin sentence array
});
let outputSentence = ''; // Create a variable to hold the pig latin sentence to be returned
pigLatinSentence.forEach((word) => { // Loop through the pig latin words
outputSentence += word + ' ' // Add each pig latin word to the output sentence with a space after it
})
return outputSentence.substring(0, outputSentence.length) + '.'; // Return the pig latin sentence
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more