4th Jul 2018, 8:49 PM
Sina
Sina - avatar
9 odpowiedzi
+ 6
Your first letter leaves the a function with count of 2 instead of 1. B won't be matched as count is 1 not the required 0. Remove the ++ on count in the if statements and increment at the end of the function.
4th Jul 2018, 9:29 PM
John Wells
John Wells - avatar
+ 5
You could do var count = 0; function a(){ var str = document.getElementById("input") var p = document.getElementById("p") p.innerHTML = ""; str.value = str.value.toUpperCase() for(var a = 0; a < str.value.length; a++) { if(str.value[a] == "A"){ p.innerHTML += ".-" } if(str.value[a] == "B"){ p.innerHTML += "-..." } } }
4th Jul 2018, 9:03 PM
Toni Isotalo
Toni Isotalo - avatar
+ 4
How is it supposed to work?
4th Jul 2018, 9:01 PM
Toni Isotalo
Toni Isotalo - avatar
+ 3
When your if is processed your count++ happens whether the test was true or false as it is part of the decision process. The only time something doesn't get processed would be in this: if (true || false) False would not be checked because of the true. It could be expression with side effects like your count++ that will not happen. if (false && true) The true expression will not be checked.
5th Jul 2018, 4:42 PM
John Wells
John Wells - avatar
+ 1
Thanks you John Wells and Thank you Toni Isotalo
5th Jul 2018, 8:33 AM
Sina
Sina - avatar
+ 1
Hey John I hpe you be good today .Thanks for your explaining. I underestood
5th Jul 2018, 7:31 PM
Sina
Sina - avatar
+ 1
https://code.sololearn.com/WvGTb8AoSWNL/?ref=app Finally I made it by myself.Tanks but it's not complete yet
5th Jul 2018, 7:31 PM
Sina
Sina - avatar
0
it's a morse
5th Jul 2018, 8:27 AM
Sina
Sina - avatar
0
Just I don't underestand why??
5th Jul 2018, 8:48 AM
Sina
Sina - avatar