#Repetition of a parameter

1 messages · Page 1 of 1 (latest)

dusky apex
#

<@&934250633580658788>

eager knoll
#

What have you tried?

random robin
#

For this one, you'll want to learn how for loops work if you don't know already

dusky apex
#

confused

#

what to do next

steep garden
#

Isn’t this just .repeat(int)

#

"x".repeat(10) will give xxxxxxxxxx

dusky apex
#

to let the user

#

input

#

the amount

random robin
#

pass in the variable into the .repeat()

silver gate
#

Nah, you just didn't ask your question well 😄

random robin
#

that you grabbed from the user

steep garden
random robin
#

make sure it's an integer

silver gate
#

Oh, you do actually just want to print lol

#

I'll leave 😶

steep garden
#
let amount = parseInt("6")
console.log("x".repeat(amount))```
random robin
#

there you go, or could just do let amount = 6

random robin
#

your presence is appreciated

steep garden
dusky apex
#

do i write my function before

random robin
steep garden
random robin
#

meeee neither

dusky apex
#

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

random robin
#

how do u want it to ask

#

thru the console?

dusky apex
#

thats the exact task

random robin
#

oh you don't need input from user

#

you just need a function that you can call with a parameter

random robin
dusky apex
#

so

#

function makex ()
{
let amount = parseInt("6")
console.log("x".repeat(amount))
}

#

like that

#

u mean wrap?

random robin
#

nope, amount needs to be a parameter

#

not defined inside the function

dusky apex
#

oh so like outside the curly

#

brackets

random robin
#

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

remote glen
dusky apex
#

or after them

#

like on the outside

random robin
#

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

dusky apex
#

just stuff like this

#

gets confusing

#

your probs surprised

#

i even done tasks

#

🤣

random robin
#

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

dusky apex
#

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

random robin
#
#

read this, and if you have issues still after this come back here and i will help

dusky apex
#

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

random robin
#

explain it to me and I can tell you why you're right or wrong

dusky apex
#

= ("")

#

that surely wont grab the input

random robin
#

nope, it'll just set it as an empty string

dusky apex
#

so i call the function

#

again?

#

in that

#

bit

random robin
#

inside the brackets when you define the function, goes the parameters for that function

dusky apex
#

so without

random robin
#

so there will be variables you want your function to use from outside the function

dusky apex
#

i call it without the brackets?

random robin
#

function makex(amount)

dusky apex
#

after the =

random robin
#

and then the amount variable inside your function will have the variable that you pass in when you call it

dusky apex
#

what could this mean

random robin
#

what programming language are you using? js?

dusky apex
#

yh

random robin
#

paste your code

dusky apex
#

function makex(6);

{
let amount = makex;
console.log("x".repeat(amount));
}

random robin
#

line 1 is wrong

#

that is not how you define a function

dusky apex
#

function name?

#

oh

random robin
#

reread that link for how to define a function

#

and let amount = makex is wrong too

dusky apex
#

rip

#

idk

#

could ya just show the answer

random robin
#

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

dusky apex
#

LOL

#

was going to try prove you wrong

#

just made it worse

random robin
#

i'd love to be proved wrong haha

dusky apex
#

do i not put the 6 there?

random robin
#

nope

dusky apex
#

that goes in the brackets?

random robin
#

you're trying to define and call a function at the same time right now

dusky apex
#

so i use the let

#

let makex

#

straight after it

#

?

random robin
#

are you guessing till you get it right :3

dusky apex
#

just tryna get it done for the sake of homework

#

knowing ill never be touching js again

random robin
#

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

dusky apex
#

im so used to skim reading

random robin
#

function myFunction(a, b) {
  return a * b;             // Function returns the product of a and b
}```
dusky apex
#

i was looking at that exact one

#

when i said should i put a let makex

#

straight after

random robin
#

that's good to hear haha

random robin
dusky apex
#

Makes sense

#

Just don’t understand why

#

10

#

Is at the bottom

#

I’m so used to python

random robin
# dusky apex 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

dusky apex
#

I kept trying to do it above

#

Oh well I’ve understood

#

Thanks for your help and time

random robin
#

did it work when you did it above?

dusky apex
#

Ye

random robin
#

yeah, so it shouldn't matter either way

#

in languages like C++ you can't use a function (above it) before it's declared

dusky apex
#

Would you also agree this is totally different to python?

#

Some more basics are quite similar

#

But stuff like this

#

Confuses me

random robin
#

in this case, it seems the same as python

#

what about it confuses you?

dusky apex
#

Oh

#

Idk tbh

#

Where I struggled with tasks before

#

I would write in python

#

Then kind of translate it

#

😂

random robin
#
{
  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

dusky apex
#

Ohhh makes sense

#

I like these comments

#

Very handy

#

Thanks for your help