Ask coding questions

← Back to all posts
JS Assignment 3
DdGen (0)

Having trouble on Exercise 4 & 5

https://repl.it/student/submissions/7232739

Voters
DdGen (0)
Commentshotnewtop
vedprad1 (732)

Just a few simple changes:

Exercise Four:

  1. There should be a space between if and the partheses.
  2. There should not be a semicolon after the parentheses.
  3. You do not need another let inside the if block.
    Like This:
function exerciseFour(value) {
  let greaterThanFive = false;
  if (value > 5) {
    greaterThanFive = true;
  }
  return greaterThanFive;
}

Exercise Five:

Well, you cannot use === for comparing strings. You have to use the equals() method. Like this:

function exerciseFive(name) {
  let isSondra = false;
  if (name.equals('Sondra')) {
    isSondra = true;
  }
  return isSondra;
}

Sneaky Method: I don't know how your sytem grades your tests, but for both of these, there is a much faster way to do it:

function exerciseFour(value) {
  return value > 5;
}

function exerciseFive(name) {
  return name.equals('Sondra');
}

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

vedprad1 (732)

Us regulars cannot see this special repl. Can you post the code here, or put it in another repl? Thanks!

DdGen (0)

@vedprad1

function exerciseFour(value){
let greaterThanFive = false;
// In this exercise, you will be given a variable, it will be called: value
// You will also be given a variable named: greaterThanFive
// Using an 'if' statement check to see if the value is greater than 5. If it is, re-assign greaterThanFive the boolean true.
if(value > 5); {
let greaterThanFive = true;
}
// Please write your answer in the line above.
return greaterThanFive;
}

function exerciseFive(name){
let isSondra = false;
// In this exercise, you will be given a variable, it will be called: name
// You will also be given a variable named: isSondra
// Using an 'if' statement check to see if the name is equal to the string 'Sondra'. If it is, re-assign isSondra the boolean true.
if(name === 'Sondra'){}
else;{}

// Please write your answer in the line above.
return isSondra;
}