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?
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) )
I have just started learning javascript so I don’t know how to do that. Can you guide me?
I have not reached “functions” yet.
What challenge are you working on post a link please?
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.
So i don’t need to use the console commands because the output will be displayed in the right bottom screen?
No you need to use console command. You just don’t need to open dev console.
So the result will be displayed in the right bottom? without hitting the “run the tests” button?
You have to hit the run test otherwise the code won’t even run. Why not try it out?
Alright i’ll try right now
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.
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
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
ok let me try. i’ll get back.
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
Where does the little cat come from??? these words are not in the code.
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") )
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