Ask coding questions

← Back to all posts
Js: Scope and the return Statement
Paultheriault (0)

Not sure how to get this code to run without errors. Primarily, I have been receiving an error that says my variable (? I think) is undefined or that is already defined (? I am so stuck). Any hints or pointers would be greatly appreciated.

// Example Code: Reference this code for the next Exercise
let school = 'Lambda';
let className = 'Intro to Web Dev'

function nameMySchool(){
let className = "Web Development Fundamentals"

// 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.
var infunction = (school, className);

// Part Two: Create a variable called 'outsideFunction' and
// assign it to the value that will be logged on
// line 11.

// Exercise Two:
// Create a Function called 'multipliesTwoNumbers'. It will take two parameters
// call these parameters 'num1' and 'num2'. Return the two parameters multiplied together.

// 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'.

Answered by vedprad1 (433) [earned 5 cycles]
View Answer
vedprad1 (433)

Exercise One Part One:

Line 7: console.log(school);
That means that var inFunction = 'Lambda';
Also Make sure the F is capitalized.

Exercise One Part Two:

Line 11: console.log(className);
That means that var outsideFunction = 'Intro to Web Dev';
This is because of the scope of each variable.

The other ones should be self explanatory.

If this answers your question, please check the checkmark on the left side of this message. Thanks and Good Luck!