JavaScript Beginner Code Question

JavaScript Beginner Code Question
0.0 0

#1

This is an excersize to practise types of variables, functions, etc in Javascript. I am getting an error while runing the code and dont know the reason after spending over 2 hours looking up the answer.

Could you take a look pls:

const number = 14;


const string = "yes";
const booleanVar = (10 > 9);
const nullVar = 0;
const undefinedVar = f = 2; var h = undefined

const pi = 3.1415926;
const piPlusOne = pi + 1;
const piMinusOne = pi - 1;
const piDividedByThree = pi / 3;
const piSquared = math.pow(3.1415926,2);
const piRoundedUp = math.floor(pi);
const piRoundedUp = math.ceil(pi);

Math.random(1); 

if (true)
{console.log ("Marco")
if (false) 
console.log ("Polo")
 }
  
}


} else { console.log ("Marco Polo")

}

// Remove _replaceMe_ and assign the variables below using x and y. 
const x = 7.5;
const y = -15;
const isXLessThanY =x<y;
const xMinusY = x-y;
const yDividedByX = ;
const xAsAString = "x";
const YToThePowerOfX = math.pov(x,y);
const yRoundedUp = math.round(y);

//move the console log at the start of the code to greet Evelyn. Do not 
modify anything else. 
let mysteryVar = 'start value';
console.log(mysteryVar);
const name = 'Evelyn';
console.log ('Good morrow');
const greeting2 = 'Farewell';

if (name.length < Math.random()*10) {
  mysteryVar = greeting1 + ', ' + name;
} else {
  mysteryVar = greeting2 + ', ' + name;
}

mysteryVar = null;

// Stretch Task: 
// Research the following string methods: includes, indexOf, slice, 
toUpperCase, toLowerCase
// Using those methods on 'sampleText', correctly remove _replaceMe_ and
assign the following variables.
const sampleText = "Isn't documentation great!";
const trueValue = sampleText.includes('great!');
const falseValue = index.(falseValue);
const fruit ["apple", "cherry", "orange"];
console.log(fruit.slice(0, 1));

const nine = nine.toUpperCase();
const cumen = cumen.toLowerCase();
const date = June -15
let date = June 16
if x > 10{
  console.log ("Winter")
  else 
  console.log ("Summer")}
}

#2

I recommend you using a code editor that highlights any syntax error like https://repl.it

Looks closely at any red squiggly lines because they are indications of syntax errors.

One error I can find is your quotes surrounding your strings are not regular “”. Try to enclose them again with regular ""s.


#3

I pasted this into Atom in a JavaScript file, and it highlighted this portion as an error:


if (name.length < Math.random()*10) {
mysteryVar = greeting1 + ', ’ + name;
} else {
mysteryVar = greeting2 + ', ’ + name;
}

I’m not sure what’s going on, but your quotes are different before and after the comma you’re trying to add into your string. Paste this over top of that and see if it works:


if (name.length < Math.random()*10) {
mysteryVar = greeting1 + ', ' + name;
} else {
mysteryVar = greeting2 + ', ' + name;
}

All I did was change the quotes.


#4

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.