JS Assignment 4: Control Flow Continued
BrianTran2 (13)

Is anyone doing LambdaSchool JavaScript pretest because I have worked for 40 minutes and I can get question 3 from assignment 4 correct.

You are viewing a single comment. View All
noahperez (0)

I`m stuck the two last questions of Ejercisice

JS Assignment 3: Introduction to Control Flow
re

function exampleExercise(value){
// !!! This is an example exercise, we will show you how to complete the following exercises here.
// !!! There is NO need to write any code for this exercise.
// !!! This exercise is ALREADY complete, Use this as reference to complete the others.

// In this exercise, you will be given a variable, it will be called: value
// On the next line create a variable called 'notEqualTo' and using a comparison operator, check to see if value is not equal to 'green'.
// Assign the results of that to 'notEqualTo'
let notEqualTo = value !== 'green';

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

function exerciseOne(value){
// In this exercise, you will be given a variable, it will be called: value
// On the next line create a variable called 'greaterThan' and using a comparison operator, check to see if value is greater than 5.
// Assign the results of that to 'greaterThan'
var greaterThan = value > 5;

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

function exerciseTwo(value){
// In this exercise, you will be given a variable, it will be called: value
// On the next line create a variable called 'lessThan' and using a comparison operator, check to see if value is less than 20.
// Assign the results of that to 'lessThan'
let lessThan = value < 20;

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

function exerciseThree(value){
// In this exercise, you will be given a variable, it will be called: value
// On the next line create a variable called 'equalTo' and using a comparison operator, check to see if value is equal to 37.
// Assign the results of that to 'equalTo'
var equalTo = value === 37;

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

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.

// 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.
const isSondraSondra = true;

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

Cwill14 (13)

@noahperez I couldn't figure it out either, but I messed around and this somehow passed, even though it doesn't make much sense to me.

function exerciseFour(value){
  var greaterThanFive = value === 10;
  // 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 Sondra = 'Sondra';
  let isSondra = name === Sondra;
  // 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) {
    let isSondra = true;
  }
  // Please write your answer in the line above.
  return isSondra;

The model solution they provided once done is the following, but I swear I did the same thing and it didn't work for me:

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){
    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'){
    isSondra = true;
  }
  
  // Please write your answer in the line above.
  return isSondra;
lvillafranca (0)

@Cwill14 Did you ever get an answer? I'm stuck here too

ReinierB (11)

@lvillafranca where are you stuck? i can help

ReinierB (11)

@lvillafranca
function exerciseThree(typeOfPizza){
let lovesPizza;
// In this exercise, you will be given a variable, it will be called: typeOfPizza
// You are also given another variable called: lovesPizza;
// Using an if/else statement assign lovesPizza to true if typeOfPizza is 'pepperoni', assign it to false if it is 'olives'
if(typeOfPizza === "pepperoni") {
return true
}
else {
return false
}

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

this works for me, but they make it seems so hard for no reason. There is no use of using "olives"

aalpmumcu (1)

@ReinierB you can also use "olives"

if(typeOfPizza === "olives") {
return false;
}
else {

return true;
}

BrianTran2 (13)

@aalpmumcu thank you! Sorry for the late reply.

BrianTran2 (13)

@ReinierB thank you. Sorry for the late reply on my part.

BrianTran2 (13)

@Cwill14 thank you . You are awesome. Sorry for the late reply on my part too.

Paultheriault (0)

@ReinierB Thank you, this example really illustrated the right syntax for me.

faziz6006 (2)

@BrianTran2 i can help with any question you dont get on the precourse for lamba , i myself am stuck on the assignment 15 , any idea ?

Exercise One: In this exercise you will be creating two functions.

// Function One: Will be called 'multiply'.
// This function will take two parameters, both numbers
// This function will return the two numbers multiplied together.

// Function Two: Will be called 'calculator'.
// This function will take three parameters,
// First will be a callback function,
// Second and Third will be numbers.
// This function will return the two numbers passed into the callback function.

// NOTE: You can use the multiply function to test the calculator function, but understand that
// other callback functions will be passed into it as a test.

faziz6006 (2)

@Paultheriault im doing th e lamda precourse work and im stuck on the assignment 15 question, any idea whats going on?

Exercise One: In this exercise you will be creating two functions.

// Function One: Will be called 'multiply'.
// This function will take two parameters, both numbers
// This function will return the two numbers multiplied together.

// Function Two: Will be called 'calculator'.
// This function will take three parameters,
// First will be a callback function,
// Second and Third will be numbers.
// This function will return the two numbers passed into the callback function.

// NOTE: You can use the multiply function to test the calculator function, but understand that
// other callback functions will be passed into it as a test.

Cwill14 (13)

@faziz6006

function multiply(num1, num2) {
   return num1 * num2;
}
function calculator(cb, n1, n2) {
   return cb(n1, n2);
}
calculator(multiply, 2, 4); // this should return 8

a callback function is a function being passed as a parameter to another function. this helps keep the code DRY (don't repeat yourself), because we can pass the calculator function all types of math operations by putting, for example, multiply and the two parameters that will go into multiply. Hope this helps!

Cwill14 (13)

@ReinierB true , and honestly it can be shortened even more. I wrote it out longer for clarity. you literally could put a ternary operator like so

let lovesPizza;
typeOfPizza === "pepperoni" ? lovesPizza = true :  lovesPizza = false;

the condition before the "?" is your "if" statement condition, the code after the "?" applies if the condition is true, the code after the ":" applies if the condition is false.

There are even shorter ways, but they are complicated

ReinierB (11)

@Cwill14 thank you! i used ternary before, it is an amazing way to do it and easy to read