📅  最后修改于: 2023-12-03 15:32:38.073000             🧑  作者: Mango
As a programmer, you may have heard of various projects that use Javascript for different purposes. From websites to mobile apps, Javascript is a popular language among developers. In this article, we will be focusing on how to use Javascript to create a program that translates text into whale talk.
Whale talk is a form of communication used by whales that involves sounds, songs, and clicks. These sounds are often used to communicate with other whales and can travel long distances in water.
To create a whale talk translator, we need to convert text into whale sounds. Here are the steps to do that:
const input = prompt("Enter some text: ");
const inputArray = input.toLowerCase().split("");
const vowels = ["a", "e", "i", "o", "u"];
const resultArray = inputArray.filter(letter => !vowels.includes(letter));
const whaleSounds = resultArray.map(letter => {
if(letter === "e") {
return "ee";
} else if(letter === "u") {
return "uu";
} else {
return letter.toUpperCase();
}
});
const result = whaleSounds.join("");
alert(result);
This program is a simple example of how Javascript can be used to create fun and interesting projects. By playing with different string manipulation techniques, we can create new and exciting ways of communicating with machines and people. Happy coding!