MODULE 4: FUNCTION WITH ARGUMENTS--

Qaybta Xirfada Sayniska iyo iwm

Moderators: Moderators, Junior Moderators

User avatar
afisoone
SomaliNet Super
SomaliNet Super
Posts: 5509
Joined: Wed Jul 22, 2009 9:46 pm
Location: We all want to become president even though Amisom controls Mogadishu

MODULE 4: FUNCTION WITH ARGUMENTS--

Post by afisoone »

Subax wanaagsan. Salaad subax is on about one hour for those who live here in Minneapolis, please don't forget that two rakat..
pray it.. Thanks.....
Ok. Today we are module 4. While I am waiting for salaad subax, let me share with you function arguments in javascript...
They are 3 ways you can give function arguments..
1. you can do this way and here is the code. You can give function values in default parameters as you can see below...
function magaceyga(name="Saciid barre",nationality="Somali")
{
console.log("name: "+name,"nationality: "+ nationality);
}

magaceyga();
2. You can the function any number of arguments and tell the function to read as an array. here is and example.

function sooDaabac(...magacArray)
{
for(let magaceyga of magacArray)

console.log("Magaceyga: "+magaceyga);

}
sooDaabac("saciid","afisoone","Barre");

3. you can do the opposite of the last function argument. You can give arguments and the display it in an array...
function fullName(firstname,middlename,lastname)
{
console.log("firstname: "+firstname+" middlename: "+middlename+" lastname: "+lastname);
}
fullName(...["Saciid","Abdirisaq","Barre"]);
These 3 ways you can give function arguments. You as you can we use dots.. It is called Spread operator

Ok.. See u next module

here is full document.

Code: Select all

<!doctype html>
<html>
<meta charset="utf-8">
<head>
<title>Isticmaalka variableka let</title>
</head>
<body>
<script type="text/javascript">
//first way
function magaceyga(name="Saciid barre",nationality="Somali")
{
	console.log("name: "+name,"nationality: "+ nationality);
}

magaceyga();
//second way
function sooDaabac(...magacArray)
{
	for(let magaceyga of magacArray)
	
		console.log("Magaceyga: "+magaceyga);
	
}
sooDaabac("saciid","afisoone","Barre");
//third way
function fullName(firstname,middlename,lastname)
{
	console.log("firstname: "+firstname+" middlename: "+middlename+" lastname: "+lastname);
}
fullName(...["Saciid","Abdirisaq","Barre"]);


</script>


</body>
</html>
Assalamu Caleykum..
Macalin Afisoone...
fanaanYG
SomaliNetizen
SomaliNetizen
Posts: 304
Joined: Tue Sep 27, 2016 5:55 am

Re: MODULE 4: FUNCTION WITH ARGUMENTS--

Post by fanaanYG »

try this

Code: Select all

<html>
<head>
<title>Love Tester</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="distribution" content="Global" />
<meta name="copyright" content="JavaScriptBank.com" />
</head>
<body>
<center>
<h1>Love Tester</h1>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function calc() {

first = document.loveform.name1.value.toUpperCase();
firstlength = document.loveform.name1.value.length;
second = document.loveform.name2.value.toUpperCase();
secondlength = document.loveform.name2.value.length;
var LoveCount=0;

for (Count=0; Count < firstlength; Count++) {
letter1=first.substring(Count,Count+1);
if (letter1=='L') LoveCount+=2;
if (letter1=='O') LoveCount+=2;
if (letter1=='V') LoveCount+=2;
if (letter1=='E') LoveCount+=2;
if (letter1=='Y') LoveCount+=3;
if (letter1=='O') LoveCount+=1;
if (letter1=='U') LoveCount+=3;
}

for (Count=0; Count < secondlength; Count++) {
letter2=second.substring(Count,Count+1);
if (letter2=='L') LoveCount+=2;
if (letter2=='O') LoveCount+=2;
if (letter2=='V') LoveCount+=2;
if (letter2=='E') LoveCount+=2;
if (letter2=='Y') LoveCount+=3;
if (letter2=='O') LoveCount+=1;
if (letter2=='U') LoveCount+=3;
}

amount=0;
if (LoveCount> 0) amount= 5-((firstlength+secondlength)/2)
if (LoveCount> 2) amount= 10-((firstlength+secondlength)/2)
if (LoveCount> 4) amount= 20-((firstlength+secondlength)/2)
if (LoveCount> 6) amount= 30-((firstlength+secondlength)/2)
if (LoveCount> 8) amount= 40-((firstlength+secondlength)/2)
if (LoveCount>10) amount= 50-((firstlength+secondlength)/2)
if (LoveCount>12) amount= 60-((firstlength+secondlength)/2)
if (LoveCount>14) amount= 70-((firstlength+secondlength)/2)
if (LoveCount>16) amount= 80-((firstlength+secondlength)/2)
if (LoveCount>18) amount= 90-((firstlength+secondlength)/2)
if (LoveCount>20) amount=100-((firstlength+secondlength)/2)
if (LoveCount>22) amount=110-((firstlength+secondlength)/2)

if (firstlength==0 || secondlength==0) amount= "Err";
if (amount < 0) amount= 0;
if (amount >99) amount=99;

document.loveform.output.value=amount+"%";
}
// End -->
</script>

<form name=loveform>

<input value="Bill Clinton" name="name1" type="text" size="20"> +
<input value="Monica Lewinsky" name="name2" type="text" size="20"> =
<input value="" name="output" type="text" size="6">
<br>
<br>
<input value="Calculate!" name="calculate" type="button" value="calculate"
onclick="calcundefined)">
</form>
</center>
</body>
</html>
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Careers - Engineering, Science & Computers”