Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScrip Problems #12. Refactor the previous code: create a function \'test\' w

ID: 3715303 • Letter: J

Question

JavaScrip Problems

#12.

Refactor the previous code: create a function 'test' which has 1 argument called 'guess'. This function will return the string values you previously used console.log() on. Then execute that function given (4) and the returned result should automatically print out in the console (being the last value in the console.)

Previous Code - use this to refractor:

answer = 4;
guess = "just dead";
if (isNaN(guess)) console.log("no numbers given"); else console.log( answer == parseInt(guess) ? "correct": "wrong");

Output:

Last console values correct

Explanation / Answer

<!DOCTYPE html>
<html>
<body>
<script>
function test(guess) {
answer = 4;
if (isNaN(guess)) {
return "no numbers given";
}
else {
var s = (answer == parseInt(guess)) ? "correct": "wrong";
console.log(s );
return s;
}
}
console.log(test(4));
</script>

</body>
</html>