+ 1

Can i have any help with this cod !

Make a function checkMailNumber (), which gets the postal code of the parameter and checks the correctness of the postal code. The function returns true if the input data contains five digits. Otherwise, false is returned. You can use JS's built-in length property to curve the length of a string Also, make a function call and test print to the console.

1st Jul 2020, 12:54 PM
Sabah RK
Sabah RK - avatar
18 odpowiedzi
+ 4
This ensures that argument length equals to 5 and each character is a digit. function double(arg) { if(arg.length !== 5) return false; // length neq 5 const digits = "1234567890"; for(const c of arg) { if(-1 === digits.indexOf(c)) // if <c> is not a digit return false; } return true; }
1st Jul 2020, 2:37 PM
Ipang
+ 4
Nice trick using NaN as boolean expression Rithea Sreng 👍
1st Jul 2020, 3:05 PM
Ipang
+ 3
Sabah RK as Ipang pointed out we are here to help guide you not do for you. Please use the 8 rules for getting help from the community. Thanks and happy coding. https://www.sololearn.com/Blog/38/8-simple-rules-to-get-help-from-the-community
1st Jul 2020, 1:25 PM
BroFar
BroFar - avatar
+ 3
<!DOCTYPE html> <html> <head> <title>check Post Cod</title> </head> <script> function checkNumber(){ var postCod= double(document.getElementById("ilo").value); document.getElementById("num").innerHTML= postCod; } function double(){ if(arguments.length = 5){ return true; } else{ return false; } } </script> <body> <input id="ilo"/> <button onclick="checkNumber()"> click</button> <h1 id="num"></h1> </body> </html>
1st Jul 2020, 1:42 PM
Sabah RK
Sabah RK - avatar
+ 3
yes only shoud get 5 digit It doesn't matter which numbers.
1st Jul 2020, 2:19 PM
Sabah RK
Sabah RK - avatar
+ 3
Rithea Sreng thank you so much 👌work perfectly
1st Jul 2020, 2:28 PM
Sabah RK
Sabah RK - avatar
+ 3
Sabah RK one more solution using a regular expression: // *** function *** const postalCode = (args) => /^[0-9]{5}$/.test(args); // Calling her console.log(postalCode("73295")); // true console.log(postalCode("7329")); // false console.log(postalCode("73a95")); // false
1st Jul 2020, 5:15 PM
JaScript
JaScript - avatar
+ 3
Double is a keyword. You cant use a keyword as a identifier (variable or function name)
2nd Jul 2020, 1:20 AM
Sali65
Sali65 - avatar
+ 3
thanx all guys
3rd Jul 2020, 7:14 AM
Sabah RK
Sabah RK - avatar
+ 2
What help you need? the community helps when they see a given effort from your side, but it is not likely to have someone do the entire work. Try to sketch the code, save it in SoloLearn and share the code's link in thread Description. Let people see it so they can conclude what to suggest. It doesn't matter if the code doesn't work, just give it a try 👌 Follow the below guide to sharing links 👍 https://www.sololearn.com/post/75089/?ref=app
1st Jul 2020, 1:09 PM
Ipang
+ 2
this what i did but i cant see the mistake
1st Jul 2020, 1:43 PM
Sabah RK
Sabah RK - avatar
+ 2
Sabah RK where are you defining what argument is https://code.sololearn.com/W9pUbAkyO1QX/?ref=app
1st Jul 2020, 1:52 PM
BroFar
BroFar - avatar
+ 2
did u get the mistake?
1st Jul 2020, 1:59 PM
Sabah RK
Sabah RK - avatar
+ 2
Sabah RK I would help, but am not sure about the specification for a correct postal code, apart from your note that it should contain five digits. Is that all the specification aspects? just considering the length?
1st Jul 2020, 2:11 PM
Ipang
+ 1
function double(arg) { if(arg.length !== 5) return false; // length neq 5 const digits = "1234567890"; for(const c of arg) { if(-1 === digits.indexOf(c)) // if <c> is not a digit return false; } return true; }
3rd Jul 2020, 12:21 PM
LitUpSeb
LitUpSeb - avatar