A Rather Long Username

@JustARatherRidi (214)
Replit won't let me change my username :D
JS Assignment 8: Scope and the Return Statement
posted to Ask by skudeva

Think of a function as a machine, with a conveyor with supplies going into it, and a finished product coming out of it.

All this question is asking you to do is to make such a machine, or 'define a function', in Javascript terms.

So let's make our machine. The first step is to decide its name, which is sayMyName in this case, and begin our definition like so:

function sayMyName

Once you've named your machine, you need to decide what supplies it's going to take in. Supplies in Javascript are called parameters. Think of parameters as boxes, each with a name. So in our case, we'll have our machine take only one box of supplies, called name going into it.

function sayMyName(name)

Next up, we'll worry about what to actually do with our supplies. In Javascript, everything that happens in a function needs to be enclosed within curly braces ({ and }), which come right after the name and parameters, like so

function sayMyName(name) {


We know we are going to get one box called name, and we can assume there will be someone's name inside the box. The question asks us to take what is inside this box, and use it to make a greeting that looks like Hello, my name is <name>.

Let's go ahead and make a variable with this greeting inside the function.

function sayMyName(name) {
    let greeting = "Hello, my name is " + name;

Notice how I added the name parameter to the end of the string. What this does is take whatever is inside our name box, and attach it to the end of "Hello, my name is ".

Finally, let's give out, or return our finished product

function sayMyName(name) {
    let greeting = "Hello, my name is " + name;
    return greeting;

And we're done!

We now have a fully working machine, but how do we use it? You use or 'call' a function like so:


What we're doing here is putting in a value of 'Dan' into the box called name of our sayMyName function. This value we assign our parameter to is called an argument. This acts as the supplies for our function.

If we run this, what we get as the finished product is "Hello, my name is Dan".

By the way your link doesn't really work, you'd have to copy your code into a Node.js repl and put a link to it here if you want others to see it.

I hope this helped, let me know if I lost you anywhere :)

Multiple .js files in one project
posted to Ask by GopeshMedayil

Let's say you have two files, index.js and utils.js in the same repl.

If you write this into utils.js and save it,

module.exports = {
    power: 9001,
    square: x => x*x

Then in index.js, you can write the following:

const utils = require('./utils.js');
console.log(utils.power);   // 9001 gets printed
console.log(utils.square(5));   // 25 gets printed

You can also do the same thing like so

const {power, square} = require('./utils.js');
console.log(power);   // 9001 gets printed
console.log(square(5));   // 25 gets printed

This way you can split your project across several files, which helps in keeping your code organized.

So you can run code from other files in your index.js this way, but no, you can't really start executing your code from anywhere other than index.js. This makes sense because if your project started executing different files each time, then it wouldn't really be a single 'project' anymore.

You can have a group of related projects though, and if that's what you want, it's probably a good idea to split it into separate repls. Then, you can put all repls within the same folder, so you can choose which one you want to run.

If you're looking to make something in specific, let me know what it is and i might be able to tell you what's the best route you can take.

Hope this helped!

😎App of the Week😎: Kognise's FontKey
posted to Announcements by katyadee

Holy crap, Kognise made that?! I swear, I thought he was looking for a good font for his project 🤣

package installation failed
posted to Ask by feelafraid
What is wrong with my login?
posted to Ask by AzureScripts

I see you've made more progress, nice job!

The problem is that you are iterating over your database object. When you say for line in database, you get 128 characters each iteration, not one line at a time (You can see this for yourself in this line of the source code). Here's why that's a problem.

Each of your hashes are 128 characters long. So in the first iteration, you get your entire first has as a string. This is why logging in with oof/oof works. Now, after your first hash, you've got a line break (\n) before your next hash. Line breaks are counted as a character, so in iteration #2, what you get is the line break followed by the first 127 characters of your second hash. The \n and 127 characters add up to 128 characters, which is why it stops there. Finally, in iteration #3, you get that last character of your second hash.

Just to be clear, these are the 3 strings you get when you iterate over database:


So as you can tell, the second hash doesnt match up with the encryption because there's a character missing in the end and there's an extra line break in the beginning.

Fixing this is actually quite easy. Instead of iterating over each 128 characters, all you need to do is just check whether the hash is in your database's content.

if the_hash in database.content:
    # Logged in successfully

Here's a working repl

Tip: Instead of printing a lot of empty lines, you can clear the screen using os.system('clear').

Hope this helped, let me know if you get stuck anywhere!

JS Assignment 8: Scope and the Return Statement
posted to Ask by skudeva

@Ejiroghene You're so close! If you look at my solution carefully, you'll see that there's a space between the is and the ". Add that space in there, and your string should look like this

"Hello, my name is "

Once you do that, you should be good!

The Fishing Game
posted to Share by AmeliaBlackwell

@AmeliaBlackwell No problem! ^^

I'd say the easiest way to get around it is by encrypting the username and password in some way. If you haven't heard of it before, try googling "caesar cipher" (it isn't as scary as it sounds). This won't exactly stop someone from figuring it out if they wanted to, but now they would at least have to read the source code to do it.

But if you really want to make sure that no one can find out, what I'd do is use Google Sheets to store everything in accounts.txt, and use their api to access and modify the data.

The Fishing Game
posted to Share by AmeliaBlackwell

How you've managed put all of this together is seriously impressive, well done! There's one small problem if you haven't noticed, anyone can come along and see what's in accounts.txt, so the whole login thing isn't exactly 100% secure 😛

Print is not working
posted to Ask by kikeventura

You have to enclose strings, like hello, in double quotes like this:

a = "hello"

Hope this helped :)

How to create a good login, signup system with python
posted to Ask by mkhoi

To save data, you use a database. If you're doing it here on repl.it, I'd say one of the easiest ways to it is with jsonstore.io, using Leon's client.

Look into it, and if you get stuck somewhere, I'd be happy to help. Good luck!

Connect to NodeJS Server
posted to Ask by mwilki7

This might be the easiest fix you've ever seen, all you have to do is literally just replace line 16 in your client side html file with this

var socket = io();

And you're set.

So you don't need any of that ip address stuff, socket.io takes care of all that for you.

Here's a working repl

As a side note, you don't really need another repl for the client, simply running the server side code should do the job as you can see here in my very own shamelessly advertised app.

Also, is there any reason you use console.dir instead of console.log? I never got what the use of console.dir is.

Running a program
posted to Ask by TimiA

Hey TimiA, while ash15khng is correct, you usually don't have more than one starting point in a project, and that's why it was made this way. In repl.it and in Python projects in general, you have something along the lines of main.py that acts as the starting point of your project. The other files in your project may contain classes, methods, or constants that you can use within your project (using import and/or open).

If you have files that run independently to each other or do different things, it's probably a good idea to make them two separate repls (using the blue 'new repl' button up top) and not two files in the same repl.

However, if your two programs are independent of each other but are related, you might want to store the two repls in one folder. You can do this in your My repls page.

Hope this helped; if something confused you, I'll be more than glad to clarify!

Is there a way to have the program execution go back to the beginning?
posted to Ask by SamuelPKuld

Whenever you need to repeat blocks of code, think of loops. If you want to execute all of the code repeatedly, just put the whole thing inside a loop :)

Working code: https://repl.it/@JustARatherRidi/Magic-8-Ball

Php running a file
posted to Ask by Jonyk56
c programming
posted to Ask by zeno99


Defining a variable in C is quite straightforward, all you need to do is follow these steps:

  • Decide what you're going to put in the variable, and choose the appropriate datatype.
  • Decide a name for your variable.
  • Assign a value to the variable.

For example, to store your age, you would approach defining your variable like so:

  • We know the age is going to be an integer, which means it is a whole number having no decimal value. In C, the datatype for storing integers is called int, so that's our data type.
  • Our variable stores an age, so we might as well call it age.
  • We can now store any number we want in our age variable (shh, C won't know).

Once you've done those 3 things, you can write out your declaration like so

int age = 42;

(Notice that ; in the end, that's something you can't forget)

And there you have it, You've just declared your variable!

Here are some other data types you can use:

float pi = 3.14;
char grade = 'A';

If you wanted to store a string, or a sequence of characters, you would use a 'character array' (you don't have to worry about what this means, you'll learn what arrays are later)

char[] username = "zeno99";

You can find dozens of great C tutorials that will make learning it easier, here are a couple ones I found

Hope this helped!

JS Assignment 8: Scope and the Return Statement
posted to Ask by skudeva

@skudeva Anytime! If you have a preferred answer, you should go ahead mark it as the correct answer :P

[Python] Getters causing an object's attributes to be manipulated
posted to Ask by lclarkejhdf

First off, you've made your question super concise and to the point, good job!

The problem here isn't with your getter returning the wrong thing, it is with lists and mutable objects in general. As you've mentioned in your example, if i did the following

x = [1, 2, 3]
y = x

Then I wouldn't be able to change x or y without affecting the other. So where you should have started thinking is how you would solve this problem in the first place.

Here, when i say y = x, what i'm doing is assigning y to the same object that x refers to, which isn't of much use because both the variables are now keeping track of the same object.

What I want to do is to make y contain the same items as x, but store them both as separate objects. You can do that like this

y = [i for i in x]

or like this

y = [*x]

Both of which essentially create a copy of x, and store that in y

Your workaround wouldnt really work, it would have done the exact same thing if you had stored the attribute in a variable and then returned it. (Which does make sense if you think about it)

Speaking of workarounds, by the way, your implementation of getters and setters sort of is one. How you would do it in Python is by using things called 'decorators'. Here's a good video explaining it.

Let me know if i lost you anywhere, and if i didnt, I'll leave extending this idea into your getter function as an exercise for you ;)

The Fishing Game
posted to Share by AmeliaBlackwell

@AmeliaBlackwell Anytime! doing caesar cipher should take you only take you around 5-10 minutes and it shouldn't be too hard at all if you've seen it before.

And yeah, using google's APIs is definitely harder, but it's also pretty interesting to learn how to do something like that and I'd say it's quite a useful skill to have so it might be worth your time. Or don't bother at all, you do you 😛


JS (+HTML) - how to save (leaderboard) data - for music jam!
posted to Ask by ThomasS1

@ThomasS1 Using jsonstore from the client is how I'd do it as well, I think it might be the simplest way to go about this.

To solve the problem, try changing this line

body: {leaderboard: leaderboard}

to this

body: JSON.stringify({leaderboard: leaderboard})

Here's a demo repl you can compare your code with.

Hope this helped!

Daily Question #4: What is your favourite, but weird word
posted to Ask by ReshiramWolfu

Damn, repl.it really needs a 'read more' button

nodejs Get random line from file
posted to Ask by mwilki7

@mwilki7 No problem! ^^

Just so you know, that does indeed mean 3 arguments, but not the way you tried to do it.

options usually means an object, with different properties acting like optional keyword arguments. For example my second argument can be { encoding: 'utf8' } to specify that the file is in utf-8.

By the way, the square brackets around , options means that that part is optional :)

Django, need to use pip installed module in installed apps
posted to Ask by newCrisco

Hey! could you share a link to the repl please?

Connect to NodeJS Server
posted to Ask by mwilki7

@mwilki7 That's just how programming is sometimes lol


Connect to NodeJS Server
posted to Ask by mwilki7

@mwilki7 But it does work, did you check my fork of your repl?

PYTHON 3, how to send simple messages
posted to Ask by thepostyboi

Honestly, if you're new to python, it won't be quite as easy as the things you've done so far, but you definitely can do it if you have the motivation to.

Making something like this depends on a lot of things really, and there's no 'one right way to do it'. Do you plan on running it here on repl.it? Are you thinking of making it a terminal app or a website with a GUI and such?

You can the tutorial that @heyitsmarcus mentioned, and there are quite a lot of tutorials online that will help you do something like this. How I would go about doing this would be something like this:

  • Have a rough idea of what you want to make
  • Keep googling till you find something close to what you have in mind.
  • See if you know all the prerequisites to the tutorial, and if you don't understand something, google that and if google won't help either, ask for help.

Good luck!

If you could ask the Repl.it team anything, what would you ask?
posted to Ask by katyadee

@theangryepicbanana honestly I think it's because its just that popular (whether you like it or not), and I'm pretty sure a good chunk of all the repls are python. So it makes sense to keep adding features to it.

How do I reverse my Cipher
posted to Ask

@heyitsmarcus Its all cool, I think I deserved it for missing that one. As you said, we're all just trying to help people out :)

How do I reverse my Cipher
posted to Ask

You've got the right idea, but there are a couple of problems in your code.

  • You've left the plaintext variable empty, but you're trying to iterate over it in your first loop. So the encryption part doesn't really do anything.
  • In lines 11 and 17, you say L2I[c] + key and L2I[c] - key. L2I[c] gives you an int in both cases, but key is a str. You can't add an integer to a string, so python throws an error.

What exactly do you want key to do?

How do I use draw image in Javascript
posted to Ask by woodyloody

Your code was right, you just forgot the <script> tag!

Here's a working repl

You'll notice I've added a couple more arguments, those are just to resize the image.

You might have noticed that it is a bit convoluted to work with the canvas API in plain javascript. You know, getting the canvas, then getting a reference to its context, making a separate <img> element, and all that just to draw an image.

So if you plan to do anything that involves a canvas, I highly recommend p5.js. It's super intuitive and it abstracts away everything wrong with the canvas API, and there's so much you can do with it. There's also the youtube channel called Coding Train. He's got really nice videos on p5.js, and it's frankly quite hard not to get inspired watching some of his videos.

I hope this helped!

TypeError: Cannot read property 'length' of undefined
posted to Ask by laksh5

The problem is at line 88. It looks like you want 2 elements in your story array, but at line 87 you close the array and open it again in the next line.

To put both your strings in the same array, remove the ] in line 87 and replace the [ with a comma in line 88. Your array should now look like this

var story =
	    ["One day, " +
		realPerfectName +
		" was walking down the street, and he/she came to a strange sight. There was chemicals oozing from their home. Curious, he/she touched the chemical and sudddenly, their body began to change. He/she started to have a headache, and he/she became " +
		perfectName +
		"!!!. " +
		perfectName +
		" was not sure about his/her powers, but in the end, he/she used it for " +
		sider + ".", // Notice the comma and the removed brackets
		"One day, " +
		realPerfectName +
		" was walking down the street, and he/she went to work as usual. He/she was experimenting with uranium, until he/she dropped it on his pet hamster. Hastily, he/she cleaned it off of him. At home, his/her hamster bit him/her, and he/she started to feel a bit strange. Woozy, he/she fell on the bed. In the morning, he/she was " +
		perfectName +
		"!!!. "]

Here's a working repl