Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Here the issue is that you have re-declared the your variable again, and you have not added an element to separate the variable from the string in the console.log().

    • First, since you've already declared the var myName, you do not need to re-declare it by typing "var" before the variable anymore.
    • Second, for your code to be able to understand that you want for it to run a string (any element in quotation mark) and a variable, you have to use " 'string ' + variableName" or " 'string', variableName".
      Note that when using the +, which is called the concatenate operator and is used to combine strings and other elements, I would advice to leave a space at the end of the string so that the string and the variable are not stuck together when printed.
      But when using the , it automatically leaves a space between the two elements.
    var myName = 'Elijah'
    console.log('My name is: ' + myName);
    
    or
    
    console.log('My name is:', myName);
    
    • A third option would be to declare you variable inside of the console.log by using template literals. These allow for one to put strings and variables together as easiliy aas the example below: But the variable has to be inside of ${The variable would be here}, it can be declared here or just called in here
    console.log(`My name is: ${var myName = "Elijah"}`);
    
    or 
    
    var myName = "Elijah"
    console.log(`My name is: ${myName}`);
    

    I hope that it helps. Keep up the good work.

  • Custom User Avatar

    Cheers. Don't give up. We get to see these type of codes to see what is possible. Just researh it, learn to understand it, and you can use it after as well. You got this.

  • Default User Avatar
  • Default User Avatar

    It would have worked if you had changed console.log() with return, and place the elements in a function. As the result of your code is not being displayed in the console, but being tested, and thus needs to have the result returned. Keep up the good work.

    ` function evenOrOdd ( number = prompt("Enter a number: ") ) {

    if (number % 2 == 0){

      return  "The number is even.";
    

    } else{

       return  "The number is odd.";
    

    }

    }`

    I hope that it helps.

  • Default User Avatar

    Thank you so much for your explanation and the function explaining it. I tested it and it worked with my assumptions in the way your functions explained. I shall look more into bitwise operations as well.

  • Default User Avatar

    I love those as well. It's so interesting. I always look up what they're about if no one explained them in the replies. It's fun to know that those fancy options exist.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This is just awesome lol. I'm loving it.

  • Default User Avatar

    Actually x is a string, so it doesn't need to be turn into a string in the context of this challenge. But it would indeed be good practice to set it the way you suggested more realistic cases where people are more likely to set x as a number type. But because this challenge asked for the values of x to be strings, it should be fine. Thank you for your insight, I had missed that out.

  • Default User Avatar

    I like how different the answers are here. I like how you solved it.

  • Default User Avatar
  • Default User Avatar

    I was wondering the same thing and this answer is just awesome. Thank you for taking the time to write all this. I shall definitely pay more attention to the data type when comparing. Thank you for your insight.

  • Default User Avatar

    I was wondering the same thing and this answer is just awesome. Thank you for taking the time to write all this. I shall definitely pay more attention to the data type when comparing. Thank you for your insight.