Ask coding questions

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

Having trouble on Exercise 4 & 5

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

Commentshotnewtop
vedprad1 (877)

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!

ARCompton14 (0)

@vedprad1

It is interesting to me that your example for number 4 works in the system, but to solve number 5 in the system it requires (name === ('Sondra)) to work properly. That is the only way it will return a completed assignment.

vedprad1 (877)

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

DdGen (4)

@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;
}