📜  LEARN JAVASCRIPTWhale Talk - Javascript (1)

📅  最后修改于: 2023-12-03 15:32:38.073000             🧑  作者: Mango

LEARN JAVASCRIPT - Whale Talk with Javascript

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.

What is 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.

Creating a Whale Talk Translator with Javascript

To create a whale talk translator, we need to convert text into whale sounds. Here are the steps to do that:

  1. Get the input text from the user.
const input = prompt("Enter some text: ");
  1. Convert the input text into an array of characters.
const inputArray = input.toLowerCase().split("");
  1. Remove all the vowels from the array.
const vowels = ["a", "e", "i", "o", "u"];
const resultArray = inputArray.filter(letter => !vowels.includes(letter));
  1. Convert the remaining consonants into whale sounds.
const whaleSounds = resultArray.map(letter => {
  if(letter === "e") {
    return "ee";
  } else if(letter === "u") {
    return "uu";
  } else {
    return letter.toUpperCase();
  }
});
  1. Display the final result to the user.
const result = whaleSounds.join("");
alert(result);
Conclusion

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!