₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,327,393 members, 8,430,766 topics. Date: Sunday, 21 June 2026 at 05:06 AM

Toggle theme

I Just Wrote My First JS Function ;D - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingI Just Wrote My First JS Function ;D (808 Views)

1 Reply (Go Down)

I Just Wrote My First JS Function ;D by Stephen0mozzy(op): 9:00pm On Dec 30, 2022
function numBtw(first, second, third) {
if (typeof first != 'number') alert('Sorry, only numbers are allowed');
if (typeof second != 'number') alert('Sorry, only numbers are allowed');
if (typeof third != 'number') alert('Sorry, only numbers are allowed');
for (let i = first; i<=second; i+=third) {
console.log(i);
}
}

numBtw(2, 98, 74);



Basically, the function receives a number within given range (i.e from first (argument) to second (argument) and the third argument is the rate at which the values should change (I nor know the math word for it). (Would currently only work in the console sha). It also kinnda guards against entering non-number values.

I norva sabi HTML DOM just yet, i'd have built it into a small web project

grin
Re: I Just Wrote My First JS Function ;D by Nobody: 9:05pm On Dec 30, 2022
Stephen0mozzy:
function numBtw(first, second, third) {
if (typeof first != 'number') alert('Sorry, only numbers are allowed');
if (typeof second != 'number') alert('Sorry, only numbers are allowed');
if (typeof third != 'number') alert('Sorry, only numbers are allowed');
for (let i = first; i<=second; i+=third) {
console.log(i);
}
}

numBtw(2, 98, 74);



Basically, the function receives a number within given range (i.e from first (argument) to second (argument) and the third argument is the rate at which the values should change (I nor know the math word for it). (Would currently only work in the console sha). It also kinnda guards against entering non-number values.

I norva sabi HTML DOM just yet, i'd have built it into a small web project

grin
Normalize using double "!==" or
3ple "===" when comparing.
Re: I Just Wrote My First JS Function ;D by Stephen0mozzy(op): 9:17pm On Dec 30, 2022
GREATIGBOMAN:
Normalize using double "!==" or
3ple "===" when comparing.
Thank you Chief. I will keep that in mind going forward
Re: I Just Wrote My First JS Function ;D by after4: 9:18pm On Dec 30, 2022
Did it work because I did see your conditional statement returning anything here

Stephen0mozzy:
function numBtw(first, second, third) {
if (typeof first != 'number') alert('Sorry, only numbers are allowed');
if (typeof second != 'number') alert('Sorry, only numbers are allowed');
if (typeof third != 'number') alert('Sorry, only numbers are allowed');
for (let i = first; i<=second; i+=third) {
console.log(i);
}
}

numBtw(2, 98, 74);



Basically, the function receives a number within given range (i.e from first (argument) to second (argument) and the third argument is the rate at which the values should change (I nor know the math word for it). (Would currently only work in the console sha). It also kinnda guards against entering non-number values.

I norva sabi HTML DOM just yet, i'd have built it into a small web project

grin
Re: I Just Wrote My First JS Function ;D by Stephen0mozzy(op): 9:22pm On Dec 30, 2022
after4:
Did it work because I did see your conditional statement returning anything here
Yes Boss it works, provided the arguments provided to the function are numbers, then it won't trigger the actions in the conditions. In my example, all three entries


numBtw(thisIsANumber, thisIsANumber, thisIsANumber);

Re: I Just Wrote My First JS Function ;D by after4: 9:48pm On Dec 30, 2022
Good

Stephen0mozzy:
Yes Boss it works, provided the arguments provided to the function are numbers, then it won't trigger the actions in the conditions. In my example, all three entries


numBtw(thisIsANumber, thisIsANumber, thisIsANumber);

Re: I Just Wrote My First JS Function ;D by sanmisamuel: 6:01pm On Jan 17, 2023
What happens if the first parameter is greater than the second parameter.

Are you trying to sum up the first and second parameter to be displayed as third parameter.

Or you want to sum the 3 parameters.

Your conditions may not pass some other test.
Re: I Just Wrote My First JS Function ;D by Thermodynamics(m): 7:44pm On Jan 17, 2023
Stephen0mozzy:
function numBtw(first, second, third) {
if (typeof first != 'number') alert('Sorry, only numbers are allowed');
if (typeof second != 'number') alert('Sorry, only numbers are allowed');
if (typeof third != 'number') alert('Sorry, only numbers are allowed');
for (let i = first; i<=second; i+=third) {
console.log(i);
}
}

numBtw(2, 98, 74);



Basically, the function receives a number within given range (i.e from first (argument) to second (argument) and the third argument is the rate at which the values should change (I nor know the math word for it). (Would currently only work in the console sha). It also kinnda guards against entering non-number values.

I norva sabi HTML DOM just yet, i'd have built it into a small web project

grin
Try to use the or "||" operator instead of typing 3 if statement, it'll shorten your code to one if statement. It's a better and cleaner way you can write this code.
Re: I Just Wrote My First JS Function ;D by Xedmark: 9:17pm On Jan 17, 2023
Lil bro challenge yourself, this looks like child's play.
Re: I Just Wrote My First JS Function ;D by Stephen0mozzy(op): 5:38am On Jan 18, 2023
Thermodynamics:
Try to use the or "||" operator instead of typing 3 if statement, it'll shorten your code to one if statement. It's a better and cleaner way you can write this code.
Thanks Chief... I know better now
Re: I Just Wrote My First JS Function ;D by Stephen0mozzy(op): 5:40am On Jan 18, 2023
Xedmark:
Lil bro challenge yourself, this looks like child's play.
k.
Re: I Just Wrote My First JS Function ;D by Deicide: 5:53pm On Jan 18, 2023
Xedmark:
Lil bro challenge yourself, this looks like child's play.
everybody gets start somewhere
1 Reply

How I Wrote My Website Code From Scratch Using AI ChatbotsWrote My First JS Code On VS Code.... Lol (pics)I Just Wrote My First Android App. Please Check It Out234

How To Get Jobs That Sponsor Visa In EuropeSEUN View Comments Under Post 2025 Agenda (IMPLEMENTED)Re: