#Repetition of a parameter
1 messages · Page 1 of 1 (latest)
What have you tried?
For this one, you'll want to learn how for loops work if you don't know already
so far just made a function called repeat
confused
what to do next
is that a way
to let the user
input
the amount
pass in the variable into the .repeat()
Nah, you just didn't ask your question well 😄
that you grabbed from the user
Yeah
make sure it's an integer
let amount = parseInt("6")
console.log("x".repeat(amount))```
there you go, or could just do let amount = 6
Yeah, however this will return an error if the user puts in a string
ummm
do i write my function before
is the user editing the code? lol
Idk what he exactly wants lol
meeee neither
i need it to ask
how many times it wants the set "x"
to be repeated
then repeat it that many times as the output
make any sense now lol
confused myself
thats the exact task
oh you don't need input from user
you just need a function that you can call with a parameter
so this?
wrap this in a function, and make amount a parameter instead
so
function makex ()
{
let amount = parseInt("6")
console.log("x".repeat(amount))
}
like that
u mean wrap?
and then you need to make makex accept a value when you call it
and instead of console.logging the result, you need to return it
+function makex(amount)
that before the curly brackets?
or after them
like on the outside
I recommend that you do some reading on how functions work, as you need to know how they work for this question, and if we just do it for you, you won't understand for your future classes/questions
ive managed to do so many other tasks
just stuff like this
gets confusing
your probs surprised
i even done tasks
🤣
I'm not surprised hahaha, just saying if we just explain it to you then you won't understand why then it'll still be just as hard in the future. But if you spend a couple minutes learning how functions work, you'd be able to do this quickly, and my hints would make sense to you
could you just write this all out for me in the actual order
so far ive been doing all the tasks
saving them
and like using them
as template sorta thing
i just find it easy
to learn
sorta makes sense
you trying to say ive done it wrong so far?
function makex(6)
{
let amount = ("");
console.log("x".repeat(amount));
}
pretty sure let amount =
bit is wrong
why do you think it's wrong?
explain it to me and I can tell you why you're right or wrong
nope, it'll just set it as an empty string
inside the brackets when you define the function, goes the parameters for that function
so without
so there will be variables you want your function to use from outside the function
i call it without the brackets?
function makex(amount)
after the =
and then the amount variable inside your function will have the variable that you pass in when you call it
what programming language are you using? js?
yh
paste your code
function makex(6);
{
let amount = makex;
console.log("x".repeat(amount));
}
nah lol
some other helper might do your homework, not me though
just against my principles to do things for someone who just wants it spoonfed instead of putting the effort in themselves and giving a good-faith attempt to do something
i'd love to be proved wrong haha
nope
that goes in the brackets?
you're trying to define and call a function at the same time right now
are you guessing till you get it right :3
just tryna get it done for the sake of homework
knowing ill never be touching js again
fine i'll succumb, in a good mood today
{
return "x".repeat(amount)
}
console.log(makex(10))```
it is so similar to the examples on the page i sent so i'm still convinced you never read it
LOL show me which
im so used to skim reading
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}```
i was looking at that exact one
when i said should i put a let makex
straight after
that's good to hear haha
if there is anything here you don't understand, please let me know
Makes sense
Just don’t understand why
10
Is at the bottom
I’m so used to python
this isn't really related to python vs js, some languages need the code where you call the function below where you actually defined the function in the same file, otherwise you're calling it before it exists, but lots of interpreted languages don't care ( i believe both js, and python it doesn't matter)
it's below it, because you're calling the function. you could call it above the function too, it doesn't matter in this case
I find this so odd
I kept trying to do it above
Oh well I’ve understood
Thanks for your help and time
did it work when you did it above?
Ye
yeah, so it shouldn't matter either way
in languages like C++ you can't use a function (above it) before it's declared
Would you also agree this is totally different to python?
Some more basics are quite similar
But stuff like this
Confuses me
Oh
Idk tbh
Where I struggled with tasks before
I would write in python
Then kind of translate it
😂
{
return "x".repeat(amount) // since we passed 10 into this function, x will repeat 10 times and return outside this function
}
let myString = makex(10) // this will pass 10 into the parameter, and set the 10 x's to be stored in the string
heres some more comments to hopefully explain better