Ask coding questions

← Back to all posts
JS Assignment 7: Arguments and Parameters
ReinierB (13)

JS Assignment 7: Arguments, I do not know what is going on, The console is printing what they asking for to be undefined, but I still get an error? im passing the second exercise, but not the first. It is a bug or am I doing something wrong that i cant see? i check stackflow some people were having the same problems without solutions.
// Exercise One:
// Step One: Create a function called 'parametersExercise'.
// Step Two: This function will need to take two parameters, call them 'param1' and 'param2'
// Step Three: The function should console log the second parameter.

// DO NOT CHANGE ANYTHING ON THE NEXT FOUR LINES!
function exerciseTwo(){
function sayMyName(parameter1){
console.log(parameter1);
}

// Continue below this line:
function parametersExercise(param1, param2) {
console.log(param2);
}

parametersExercise();

// Exercise Two:
// Step One create a variable called 'myName' and assign it the a string of your name.
// Step Two: Call the function called "sayMyName",passing the 'myName' variable as it's only argument.
// NOTE: You do NOT need to create the function (sayMyName), doing so will break the test.
// It has been created for you.
let myName = "Reinier";
sayMyName(myName);
}
exerciseTwo();

Commentshotnewtop
Shif (3)

Fellow student here. Came for some insights and found it hard to find any when someone is asking another poster for all the answers to problem sets they are having issues with!
TL:DR
Please don't highjack asks.

  • I struggled with Assignment 7
  • I thought my code was right but I kept failing
  • Turns out my code was fine
  • But the instructions were confusing at least or even faulty

Key points:
>Solve Excersize 1 on line 5
>Solve Excersize 2 on line 24

*you do not need to literally continue below this line when the instructions say so!

// Continue below this line:
// Exercise Two:
// Step One create a variable called 'myName' and assign it the a string of your name.
// Step Two: Call the function called "sayMyName",passing the 'myName' variable as it's only argument.
// NOTE: You do NOT need to create the function (sayMyName), doing so will break the test. 
//       It has been created for you.```
sherifaelalfi (1)

This was really helpful! I had the exact same issue and as soon as I removed my code to line 5 it was marked correct! Thank you! @Shif

Sobeshot (0)

@Shif This is exactly what I needed. Thanks for the tip!

TheDrone7 (560)

So I went through what you posted. Firstly, the part where it says DO NOT CHANGE THE NEXT FOUR LINES, you never closed the function named exerciseTwo(), so first add a closing bracket after that }. Nextly while calling the exerciseOne function, you need to pass 2 parameters for it to print something otherwise the values for param1 and param2 will default to undefined. Hope this helps. Let me know if it still doesn't work. Nextly, here are some tips while asking questions, use three backticks ``` to enclose code blocks. Finally, it would be easier if you shared the link to repl itself which would allow us to have a look at the error ourselves.

Vandesm14 (726)

You needed to pass the parameters to the first function paremetersExercise():

parametersExercise('foo', 'bar');

The repl: https://repl.it/@Vandesm14/InfamousIdolizedHashmaps

Please mark this as answered if I helped your problem 👍

ReinierB (13)

@Vandesm14 i see! I guess i wasn't understanding the question. passing the param1 and 2. Thank you

Vandesm14 (726)

@ReinierB

Please mark this as answered if I helped your problem :) ;) :P ;P

ReinierB (13)

@Vandesm14 // Exercise One:
// Step One: Create a function called 'parametersExercise'.
// Step Two: This function will need to take two parameters, call them 'param1' and 'param2'
// Step Three: The function should console log the second parameter.

// DO NOT CHANGE ANYTHING ON THE NEXT FOUR LINES!
function exerciseTwo(){
function sayMyName(parameter1){
console.log(parameter1);

}

// Continue below this line:
function parametersExercise() {
console.log('param2');
}
parametersExercise('param1', 'param2');

// Exercise Two:
// Step One create a variable called 'myName' and assign it the a string of your name.
// Step Two: Call the function called "sayMyName",passing the 'myName' variable as it's only argument.
// NOTE: You do NOT need to create the function (sayMyName), doing so will break the test.
// It has been created for you.
let myName = "Reinier";
sayMyName(myName);
}
exerciseTwo(); `

this is what i have! im still failing to this! the instructions are not well put or it is me that dont get it all.

1Voice90 (0)

I am having a syntax error i know my code is correct. but during calling out the function it does not turn colors.. I hope i get reply

RobertLacy (0)

Just Wondering if you ever got this to work? I could get both to pass but not together. individually they would both pass. the first one would fail as soon as I would start "sayMyName" for exercise Two

JwalyaOza (3)

i just cannot understand what the hell is happening with me.. despite of doing exactly what you said and eventually getting my second exercise right i'm still not able to clear the first exercise and whenever i press run tests button they say "expected undefined to be function" what the hell does that mean? do i have to print anything? please is there anyone who can find me suitable and correct way of solving the exerscise 1?

ReinierB (13)

@JwalyaOza Hi, i skipped the first one, kept going because i didn't manage to pass the first one! it is crazy. just keep going and come back later on

JwalyaOza (3)

@ReinierB . do you think there might be something wrong with my server? do you think that main reason behind not being able to clear the 1st exercise would be unstable server of mine? i really don't think so.. what yaa say? anyways i was able to get my 2nd exercise right and i submitted it anyway. lets see what happens further

ReinierB (13)

@JwalyaOza it is weird i managed to pass the second one too, but the first one is badly written or the way the asked..

function exerciseTwo(){
function sayMyName(parameter1){
console.log(parameter1);

}

// Continue below this line:
function parametersExercise(param1, param2) {
console.log(param2);
}

parametersExercise("param1", "param2");

// Exercise Two:
// Step One create a variable called 'myName' and assign it the a string of your name.
// Step Two: Call the function called "sayMyName",passing the 'myName' variable as it's only argument.
// NOTE: You do NOT need to create the function (sayMyName), doing so will break the test.
// It has been created for you.
let myName = "Reinier";
sayMyName(myName);
}
exerciseTwo();

JwalyaOza (3)

@ReinierB. By the way if you do not mind.. I gotta have someone's guidance in order to finish the assignment as quick as possible...And I think you can help me. Actually despite of performing couple of codes I am not able to get the correct answer of any of the exercises of Js assignment 8.. and I have to finish it as fast as possible in order to continue further..So can you please help me to find the correct answer of the exercises in assignment 8.. I really need help. It's my humble request to you and also the one who are doing the same thing alongside...Please guide me

ReinierB (13)

@JwalyaOza Sure, share your code! or i can send to you how i did

ReinierB (13)

@JwalyaOza

let school = 'Lambda';
let className = 'Intro to Web Dev'

function nameMySchool(){
  let className = "Web Development Fundamentals"
  console.log(school);
}

nameMySchool();
console.log(className);
// Do not change any code above this line!


// Exercise One: 
// Part One: Create a variable called 'inFunction' and 
//           assign it to the value that will be logged
//           on line 7.
let inFunction =  "Lambda";

// Part Two: Create a variable called 'outsideFunction' and
//           assign it to the value that will be logged on  
//           line 11.
let outsideFunction = "Intro to Web Dev";


// Exercise Two:
// Create a Function called 'multipliesTwoNumbers'. It will take two parameters
// call these parameters 'num1' and 'num2'. Return the two parameters multiplied together.
 function multipliesTwoNumbers(num1,num2) {
   return num1 * num2;
 }

// Exercise Three:
// Create a function called 'sayMyName'. It will take one parameter. Call this
// parameter 'myName'. Return the phrase "Hello, my name is " and the myName parameter.
// eg: if name is 'Dan' it should return the string: 'Hello, my name is Dan'.
function sayMyName(myName) {
  
  return "Hello, my name is " +  myName ;
}
sayMyName(myName);
ReinierB (13)

@JwalyaOza here is the code, but before you move on, try to understand why at least

JwalyaOza (3)

@ReinierB. Hey pal.. thanks a lot for helping me to complete this assignment. Thank you so much I hope I also get helpful to you someday. by the way the only thing I wasn't able to understand was what to write next to infunction.. and now my doubt has got cleared. Thank you friend. And now let's hope it gets accepted and something like what happened in the 7th assignment does not gets repeated

ReinierB (13)

@JwalyaOza it is my pleasure! by helping others is the best way to learn... :)

JwalyaOza (3)

@ReinierB. Man I seriously need your help once again for the quarries which I am getting In the 9th assignment. Please pal I need your guidance once again in order to finish the 9th assignment.. I hope you can help buddy

JwalyaOza (3)

@ReinierB. I really need help to complete the js assignment 9. i hope you can give me from proper guidance so that i can complete it and move ahead. please do it buddy.

ReinierB (13)

@JwalyaOza `// Exercise One: Create a vaiable called 'numbersArray',
// assign it to an array containing 5 numbers (any numbers).
let numbersArray = [2,34,4,5,6];

// Exercise Two: Create a variable called 'cars',
// assign it to an array containing the names of three cars.
let cars = ['honda', 'Hunday', 'Chevy'];

function exerciseThree(bandsArray){
// Exercise Three: In this function you will be given an array called 'bandsArray'.
// console log the third band in the array.
// Note: DO NOT create a new array in this challenge.
// Note: Remember that array indecies start at 0.
console.log(bandsArray[2]);
}

function exerciseFour(citiesArray){
// Exercise Four: In this function you will be given an array called 'citiesArray.
// re-assign the fourth city in the array to 'Santa Fe'.
// Note: DO NOT create a new array in this challenge.
// Note: Remember that array indecies start at 0.
citiesArray[citiesArray.length -2];
citiesArray[3] = 'Santa Fe';

// Complete your work on the line above.
return citiesArray;
}

here is my solution! remember to try to understand why

JwalyaOza (3)

@ReinierB . sure man thanks for helping and i will try my level best to understand it well and do it in a precise manner and if i'll get any quarries i'll contact you.but first.. i'll try to understand it well and get my concept cleared about the phenomenon behind that particular assignment

royohms (0)

@ReinierB were you able to get the model solution? I am currently stuck trying to figure it out. any help on what I should do? I am still yet to get anyone right

samanthar110 (0)

take out the last curly bracket if you didn't already