+ 1

How to do it so if the prompt contains "a" do something?

https://code.sololearn.com/W0hObMWqGlD0/?ref=app

3rd Apr 2022, 6:59 PM
Spencer Pawlik
Spencer Pawlik - avatar
10 Answers
+ 3
You can use includes() like this function morse() { if (words.includes("a")) { code=code+".- "; }; if (words.includes("b") ){ code=code+"-... "; }; alert(code); } edit: "abcdefghijk".includes(words) like this?
3rd Apr 2022, 7:15 PM
Jayakrishna 🇼🇳
+ 2
Yes but I want it to be if you put in the prompt ab so it will be .- -... (morse code). But it won't show anything.
3rd Apr 2022, 7:05 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 2
Lego in Motion Why to use loop and includes function when you can use replaceAll function. words = words.replaceAll("a", ".- "). replaceAll("b","-... "). replaceAll("c", "-.-. "); alert(words);
4th Apr 2022, 6:15 AM
AÍąJ
AÍąJ - avatar
+ 1
What is test("b") there?
3rd Apr 2022, 7:01 PM
Jayakrishna 🇼🇳
+ 1
Oops! Now it's good!
3rd Apr 2022, 7:02 PM
Spencer Pawlik
Spencer Pawlik - avatar
3rd Apr 2022, 7:02 PM
ShadowCipher
ShadowCipher - avatar
+ 1
Check the code again, I added an if statement
3rd Apr 2022, 7:09 PM
ShadowCipher
ShadowCipher - avatar
+ 1
Oh yes thanks. But if I want to do the whole alfabet and any letters together I would have to do literally bilions of if statement. Thanks for trying to help though.
3rd Apr 2022, 7:14 PM
Spencer Pawlik
Spencer Pawlik - avatar
0
Are you trying to convert an input string to morse code? If yes....just do a "for of" loop on the string. I'm sure you can use a "switch case" construct on strings in JavaScript, might be a bit tidier.
3rd Apr 2022, 7:32 PM
rodwynnejones
rodwynnejones - avatar
0
Hello
4th Apr 2022, 5:22 PM
Daniyal Abdollahi
Daniyal Abdollahi - avatar