Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,503 members, 7,819,826 topics. Date: Tuesday, 07 May 2024 at 01:40 AM

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

Nairaland Forum / Science/Technology / Programming / I Just Wrote My First JS Function ;D (617 Views)

Wrote My First JS Code On VS Code.... Lol (pics) / Wrote My First HTML Page. / I Just Wrote My First Android App. Please Check It Out (2) (3) (4)

(1) (Reply) (Go Down)

I Just Wrote My First JS Function ;D by Stephen0mozzy: 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.

4 Likes

Re: I Just Wrote My First JS Function ;D by Stephen0mozzy: 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: 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);

1 Like

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.

2 Likes

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: 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: 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)

I Need A Laravel Developer / Session In PHP / Static Page Problem Need Help

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.