Share your repls and programming experiences

← Back to all posts
Is this code invincible?
h
RohilPatel (799)

Ok, so I have made some code, and I have been working on trying to make my code more advanced and less noob-like. I've spend some time going through all the lines of code and checking possible errors with it. I have tried to make friendly messages to all the possible entries that happen with using some checks. I probably could make this cleaner with a switch, but it didn't really work for me when I tried, since I'm checking for 2 variables. My challenge for you is trying to get an error when injecting something into the function. If you can do that, then let me know down below, and I want to fix it. Lol, have a good day. I really think that I've minimized my code well, to only 9 lines as of right now. Some of you guys would need at lest 25 lol.

Commentshotnewtop
HahaYes (893)

Also pls ask category?

HahaYes (893)

What is going on with Cycle farming, all I did to get cycles was posting good content and funny jokes

HZLPY (21)

cough cough upvote farming cough cough

HZLPY (21)

@HZLPY + the title is a question, shouldn't this go in the ask category?

also this is literally less than 30 lines, you didn't put any effort into the repl or the post

mamamia5x (68)

You should see how repl was a few months ago. It was full of even more low effort posts. @HZLPY

RohilPatel (799)

He makes no sense lmao. He thinks this is a low effort post since he knows he is better then him, and also, he might be she, idk. Srry. @mamamia5x

HZLPY (21)

@RohilPatel literally nobody understood that sentence. Also it is a low effort post. Less than 30 lines total.

Imthebestthe (92)

@HZLPY it doesn’t matter that you have the inebility to make something that people will actually enjoy. Ok?

RohilPatel (799)

Yes. I'm trying to work on making my js cleaner, and I decided to start small. @Imthebestthe

HZLPY (21)

@Imthebestthe i mean where's your proof???

Imthebestthe (92)

@HZLPY. Ok. I will talk in a way you little timmies can understand; don't be toxic and quite frankly, this single 30ish code Is better than most all of YOUR codes. to the ones you just Forked.OK? and you cant chat about me cause I think that although this doesn't have much right now, doesn't mean it doesn't have potential. so. shush. don't chat. and let this guy do his coding.

RohilPatel (799)

Wooowwwww. Hazelpy forks code??? I’m going to add that on to everything lol. @Imthebestthe

HZLPY (21)

@Imthebestthe i don't fork my projects lol

AdCharity (1264)

@RohilPatel Wooowwwww open source (github and repl) exists for a reason. I’m going to add that on to everything lol.

RohilPatel (799)

Ok, he spreading fake news? That ain't cool lmao @HZLPY

ipastrano (242)

@Imthebestthe @HZLPY @RohilPatel Please don't argue or name-call; Replit is a place to learn, share your programs, and provide and take constructive criticism so that the community can grow. If you feel that the code breaks the rules/guidelines of Replit, please report it to the mod team so they can investigate.(remember not to abuse this though, as it can get you a ban!)

ipastrano (242)

@RohilPatel :) Just reminding people of the rules.

AdCharity (1264)

:l how is this invincible? Invincible code is no code at all.

StudentFires (327)

Tip: just use TypeScript and your code will be mush easier.

StudentFires (327)
export default Object.freeze(
	(price, rate) => {
		switch(true)
		{
			case typeof price !== `number`:
			case typeof price !== `number`:
			case [price, rate].filter(isNaN).length !== 0:
			{
				throw new Error(`Numbers only`);
			}
			case price < 0 || rate < 0:
			{
				throw new Error(`Not Possible (Positives Only)`);
			}
			default:
			{
				return price + (price * rate / 100);
			}
		}
	}
);

Allows only positive numbers, and the function itself cannot be modified and obeys scope.

Coder100 (3041)

Broke!
calculateItemCost(1);

Coder100 (3041)


bad
this code isn't invincible
it has been broken RIGHT HERE: just do parseInt like a real javascript!
Also stop using parentheses in returns

[deleted]

return function is without this ()

RohilPatel (799)

Yes it is, if u want to return something @Zuhdi28

[deleted]

@RohilPatel maybe you forgot to call the function?!

RohilPatel (799)

Everything works.... I don't want to call the function. @Zuhdi28

[deleted]

@RohilPatel debug it in visual studio code