Array does not work in Javascript -


i tried make function returns array, output should "my name sarah adam" not return anything

/*global s:true*/ var m = 'my name '; function updatemsg(h) {     "use strict";     var el = m + h;     s = ['adam', 'joseph'];     return s; } var n1 = document.getelementbyid("msg"); n1.textcontent = updatemsg("sarah")[0]; 

you returning s (the array) - think want return concatenated message. in:

updated include variable last names

var m = 'my name ';    function updatemsg(h, index) {    "use strict";    var el = m + h;      // array of last names    var s = ['adam', 'joseph'];      return el + ' ' + s[index]; // return concatenated string instead  }  var n1 = document.getelementbyid("msg");    n1.textcontent = updatemsg("sarah", 0); // invoke param    // console log (confirmation)  console.log(updatemsg("sarah", 0));  console.log(updatemsg("meenah", 1));
<div id="msg">    hw  </div>


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)