Week 5: Assignment 1 Practice Set Homework - Functions & Input Validation

Answers

by Lucille Kenney

HTML

<h3>Open the console to see the output from this code</h3>
<p>There are two exercises in this practice set</p>
<ol>
http://jsfiddle.net/lakenney/w4pjeesw/#update    <li>In the first, you must write the logMessage() function that will make the call on line 6 write the argument to the console. </li>
    <li>In the second, you will add input validation to this function so that the test cases work. If you've done it correctly, test cases 1-3 should output a truncated string (or the original, if the "targetLength" value isn't greater than the string length) , while test cases 4 and 5 will output the string "Invalid Input".</li>
</ol>

JavaScript

/*  
#1
This code is calling on a function logMessage(), that should accpet a single parameter, and write that parameter to the console.  No input validation is required - just echo the parameter to the console. Write the logMessage() function so that this code works. 
*/
var name = "Ellen Ripley";
logMessage("My name is "+ name);

function logMessage(name) {
    
}
console.log(logMessage);