+ 2

This is a morse code code. If I put ab it will alert .- -... and thats right. But if I put ba it will also put .- -...

Third question for this code. https://code.sololearn.com/W0hObMWqGlD0/?ref=app

3rd Apr 2022, 7:20 PM
Spencer Pawlik
Spencer Pawlik - avatar
5 odpowiedzi
+ 2
No. I used i.includes("a"), but you are using words.includes("a") tempary variable i contains single characters extracted from words....
3rd Apr 2022, 7:36 PM
Jayakrishna 🇮🇳
+ 2
Almost! Just if I put 2 letters in any order it shows .- -... twice and remember that I'm gonna add more letters later.
3rd Apr 2022, 7:34 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
If it is "ba" Or "ab" , both include a and b so both are true.. If you want in a row as input sequence, use loop and do it in sequence by splitiing input... edit: like this : Lego in Motion function morse() { for(var i of words){ if(i.includes("a")) { code=code+".- "; }; if(i.includes("b")) { code=code+"-... "; }; } alert(code); }
3rd Apr 2022, 7:26 PM
Jayakrishna 🇮🇳
+ 1
Oh yes! I didn't see that!
3rd Apr 2022, 7:37 PM
Spencer Pawlik
Spencer Pawlik - avatar
+ 1
YEEEEEEEES! THANK YOU!
3rd Apr 2022, 7:38 PM
Spencer Pawlik
Spencer Pawlik - avatar