Intermediate Algorithm Scripting - Arguments Optional

So i understand that this is like incomplete at best… likely less than efficient… possibly just not even gonna work… maybe even something yall might just giggle at when you see it… but im wondering if im heading in the right direction even… with any part of this even…any hints or suggestions…
or should i and digitally dowse this whole attempt in some digital lighter fluid & code in a zippo… burn it downn???
help?
Your code so far


const isNum = function(num){
  return(Number.isInteger(num))
}




function addTogether() {
  let values = Object.values(arguments)
  let primaryVal = values[0]
  let result = 0
    
  let priorPlus = function(numb){
    result =  primaryVal + numb
    return result

    }
// has to add two numbers passed as parameters and 
// return the sum
   if(values.length === 2 && Number.isInteger(values[0]) !== true && Number.isInteger(values[1]) === true){
      result = values[0] + values[1] 
      return result
    }
// check if any of the numbers are actual numbers, //otherwise return undefined 
  if(values.length <= 2 && (Number.isInteger(values[0]) !== true || Number.isInteger(values[1])) !== true){
      return undefined
    }

//if only 1 argument return a function that uses that number and expects 
//another one, to then add it.
  if (values.length < 2 && Number.isInteger(primaryVal)){
    return priorPlus()
    }
  
 
  

  }  


console.log(addTogether(2,3))

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Arguments Optional

Link to the challenge:

That looks like it has all the right pieces of logic.

Do you need to check if the arguments are an integer?

So after poating that i went to town with whatever this is… now my question comes with an analogy to context…

pretend im a highway engineer and ive built 60% of this hon ramp off ramp thingy but it has to follow zone laws x, y z and has to connect at a very specific point, two different specific points to weight the context,
whats been built has to connect to where ever specific
while following the zoning parameters…

there is NO budget for any kind of ENTIRE demolition and redesign

this is my feels right now… im so close to being able to teach myself HOW to “javascript”…

how do i connect my OWN overpass design to
what i need to
how i need to do it
what do i need to do to finish this build
preferably the lightest sprinkle of a hint please
:crazy_face: :confounded: :woozy_face: :face_with_spiral_eyes: :cyclone: :dizzy_face:

:orange_heart: :orange_heart: :orange_heart: :orange_heart: :orange_heart: :orange_heart::orange_heart: :orange_heart: :orange_heart: :orange_heart: :orange_heart: :orange_heart:

:innocent: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face: :innocent:


const isNum = function(num){
  return(Number.isInteger(num))
}




function addTogether() {
  let values = Object.values(arguments)
  let primaryVal = values[0]
  let result = 0

    
  let priorPlus = function(numb){
    result =  primaryVal + numb
    return result

    }
// has to add two numbers passed as parameters and 
// return the sum
   if(values.length === 2 && Number.isInteger(values[0]) !== true && Number.isInteger(values[1]) === true){
      result = values[0] + values[1] 
      return result
    }
// check if any of the numbers are actual numbers, //otherwise return undefined 
  if(values.length <= 2 && (Number.isInteger(values[0]) !== true || Number.isInteger(values[1])) !== true){
      return undefined
    }

//if only 1 argument return a function that uses that number and expects 
//another one, to then add it.
  if (values.length < 2 && Number.isInteger(primaryVal)){
    return priorPlus()
    }
  
 
  

  }  


console.log(addTogether(2,3))

Is the task to only work on integers and not decimal numbers?

Also

Why do these conditions disagree with each other?

are you asking while already knowing
or genuinly
no cinicism… just wondering cuz i thought there were no decimals it was either data type = number or else === false

Compare

To the task description.

There is only one data type for numbers, but the individual number can be a decimal number or an integer.

are you refering to the type difference between
ex: 6 && “6” && 6 && [6] && {“1”:6} &&{[6]}
or …
cuz currently in context
my brain thinkings are prefaced with

4 , (and i guess 1.2) should are
data_types === Number === true

“4” {“1”:6} {[6]}
are …
data_types === Number === false

is that not the case… or worse
not even relevant response content
:face_with_open_eyes_and_hand_over_mouth: :fearful: :scream: :face_with_open_eyes_and_hand_over_mouth:

Right, 1.2 and 6 are both valid numbers, but 1.2 is not an integer

This feels like your saying what i thought i was doing haha…
what am i missing :dart: :no_entry_sign: :no_entry: :no_entry_sign:

You need a way to check the type of a variable. I’d look through older challenges or Google ‘javascript check if variable is number’

There are 2 possible ways to do this check.

now im confused and i still dont quite know how


const isNum = function(num){

  return(Number.isNaN(num) !== true)
}






function addTogether() {
  
  let values = Object.values(arguments)
  if(Number.isNaN(values[0])){
    return undefined
  }
  let primaryVal = values[0]
  let otherVal =   values[1]

  let result = 0

    
  let priorPlus = function(numb){
    result =  primaryVal + numb
    console.log(numb)
    return result

    }
// has to add two numbers passed as parameters and 
// return the sum
   if(values.length === 2 && Number.isNaN(values[0]) !== true && Number.isNaN(values[1]) !== true){
      result = values[0] + values[1] 
      
      return result
    }
// check if any of the numbers are actual numbers, //otherwise return undefined 
  if(values.length <= 2 && (Number.isNaN(values[0]) === true || Number.isNaN(values[1])) === true){
      return undefined
    }

//if only 1 argument return a function that uses that number and expects 
//another one, to then add it.
  if (values.length < 2 && Number.isNaN(primaryVal) !== true && Number.isNaN(otherVal)){
    return priorPlus(otherVal)
    }
  
 
  

  }  


console.log(addTogether(2,3))
console.log(addTogether(5))
             [num1 , num2] = arguments 

^^^^game changing A++ data access point^^^^^^

This part looks like it should work

But here you are doing something confusing. You could have fewer than 2 values but you are checking two of them?

This function is close, but you need to check if the numb is actually a number too.

you are using arguments that has not ben declared yet.

The arguments object is always declared inside of every non-arrow function

1 Like

@JeremyLT
im still working this original build. and i just saw this bit … am working in replit on making it functional… if i got any more Q’s to ask… can i drop em in your DM?
or is here still the appropriate means to communicate?
(I only ask as i did “solve it” in curriculum)

@a4addel Happy Coding My Dood :slight_smile:
also appreciate anybody taking the time and lending a fresh pair of eyes …

and there brain to help…

Im REALLY trying to get a handle on helper functions… any links?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.