+ 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.
15 Respuestas
+ 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;
}
+ 4
Nice trick using NaN as boolean expression Rithea Sreng 👍
+ 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
+ 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>
+ 3
yes only shoud get 5 digit It doesn't matter which numbers.
+ 3
Rithea Sreng thank you so much 👌work perfectly
+ 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
+ 3
Double is a keyword. You cant use a keyword as a identifier (variable or function name)
+ 3
thanx all guys
+ 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
+ 2
this what i did but i cant see the mistake
+ 2
Sabah RK where are you defining what argument is
https://code.sololearn.com/W9pUbAkyO1QX/?ref=app
+ 2
did u get the mistake?
+ 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?
+ 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;
}