How to view the output of the code in exercises?

How to view the output of the code in exercises?
0

#1

I am confused. I want to view the output of the code before i click the “Run the Tests” button. Because after clicking the “Run the Tests” button there is no way to see the output. Is there a way to see the output of my code or am i missing something?


#2

Fire up dev console.

You call console.log(..) in the point of your interest. If you want to test with custom input, you also use console.log(..) with custom function call.

Click run test.

Example

function fn() {
    ...
    console.log( someValue )
    ...
}
console.log( fn(customInput) )

#3

I have just started learning javascript so I don’t know how to do that. Can you guide me?


#4

I have not reached “functions” yet.


#5

What challenge are you working on post a link please?


#6

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/word-blanks


#7
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";

  // do some work with result...
  // log the value of result at this point
  console.log(result)

  // do some work with result...
  // log value of result at this point
  console.log(result)

  return result;
}

// For logging particular function call
console.log( wordBlanks("dog", "big", "ran", "quickly") )

Opening up the dev console is usually f12. Or you don’t have to in this case because the result will be logged at the bottom right screen.


#8

So i don’t need to use the console commands because the output will be displayed in the right bottom screen?


#9

No you need to use console command. You just don’t need to open dev console.


#10

So the result will be displayed in the right bottom? without hitting the “run the tests” button?


#11

You have to hit the run test otherwise the code won’t even run. Why not try it out?


#12

Alright i’ll try right now


#13

Here’s my code:

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "";
  result = "I saw a " + myAdjective + " " + myNoun + "that " + myVerb + " " + myAdverb; 

  console.log(result)

  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

when i hit the “Run the tests” button, the right bottom window only shows the observations, not my output.


#14

Here’s the output that it shows:

// running test
wordBlanks(“dog”, “big”, “ran”, “quickly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
wordBlanks(“cat”, “little”, “hit”, “slowly”) should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
// tests completed


#15

In that case open up the dev console and look for the console tab. If you are using chrome and window, the shortcut is f12


#16

ok let me try. i’ll get back.


#17

Here’s what the console tab shows:

I saw a big dogthat ran quickly
frame.js:87:11
I saw a little catthat hit slowly frame.js:87:11
I saw a big dogthat ran quickly
word-blanks:26:3
I saw a little catthat hit slowly word-blanks:26:3
I saw a that


#18

Where does the little cat come from??? these words are not in the code.


#19

Remember, the test itself calls the function multiple times with different input.

If you want to see the result of specific output do this.

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  // Your code below this line
  var result = "";
  result = "I saw a " + myAdjective + " " + myNoun + "that " + myVerb + " " + myAdverb; 

  // Your code above this line
  return result;
}

// Change the words here to test your function
console.log( wordBlanks("supply your own inputs") )

#20

Ok i did that. Now it shows this output:

I saw a big dogthat ran quickly
word-blanks:26:3
I saw a little catthat hit slowly word-blanks:26:3
I saw a that word-blanks:26:3
[Show/hide message details.] Error: e is undefined