You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
functionargChecker(){vararg=0;vari=0;while(i<arguments.length){arg+=arguments[i];i++;}alert("The total value is "+arg);alert(arguments.length);}argChecker(10,23,5,6,9,8,5);/*Notes*It returns the total value and the arguments length;*/
Output
3. Change Text Node Snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><inputtype="button" value="Remove and replace" onclick="change('dis1','I\'m not a Joker i\'m a hacker')"><h1id="dis1">This is Joker</h1><h1id="dis2">This is Hacker</h1><scriptsrc="js.js"></script></body></html>
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><inputtype="button" value="Remove and replace" onclick="change('dis2','My name is hacker')"><h1id="dis1">This is Joker</h1><h1id="dis2">This is Hacker</h1><scriptsrc="js.js"></script></body></html>
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><inputtype="button" value="Remove and replace" onclick="change('dis2','My name is hacker')"><h1id="dis1">This is Joker</h1><h1id="dis2">This is Hacker</h1><scriptsrc="js.js"></script></body></html>
JavaScript
functionchange(id,texts){varnode=document.getElementById(id);node.removeChild(node.childNodes[0]);}/*Notes*We use childNodes insted of firstChild.*/
Output
Example 3
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><inputtype="button" value="Remove and replace" onclick="change('dis2','My name is hacker')"><h1id="dis1">This is Joker</h1><h1id="dis2">This is Hacker</h1><scriptsrc="js.js"></script></body></html>
JavaScript
functionchange(id,texts){varnode=document.getElementById(id);node.removeChild(node.childNodes[0]);varnewnode1=document.createElement("hr");node.appendChild(newnode1);}/*Notes*This example remove the first element and replace with an hr tag.*/
Output
4. Outputting Strings Methods Snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
document.write("5+4 ",5+4,"<br>");//use this methoddocument.write("5+4 "+5+4+"<br>");//don't use it/*Notes*The number one method is works fine.*The number two method is concate the number with the string.*We can use (,) instead of using (+) but it does not work in alert box.*/
Output
5. Increment Technic Snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
vara=5;a++;alert(a);alert(++a);/*Notesa++ //print this out on screen and then increment the value.a-- //print this out on screen and then decrement the value.++a //increment the value and then print it out on screen.--a //decrement the value and then print it out on screen.Ex:var a=5;alert(a++) // it does not work.alert(++a) // it's right.*/
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
functionarrSome(arr1,userInp){for(a=0;a<arr1.length;a++){if(arr1[a]===userInp){returntrue;}}returnfalse;}varuserarr=newArray(5);for(a=0;a<userarr.length;a++){userarr[a]=Number(prompt("Enter numberic value"));}varmyVal=arrSome(userarr,2);alert(myVal)/*Notes*It is the code of sone() Array method*/
Output
7. Arguments Snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
functiongetArgs(){vartotalArgs=0;for(u=0;u<arguments.length;u++){totalArgs+=arguments[u];}returntotalArgs;}vara=getArgs(1,2,3,6,5,4,9,5);alert(a);/*Notes*It is returns the all arguments value.*/
Output
8. Array as Argument Snippets
Example 0
HTML
<!DOCTYPE html><html><head><title>This is the title</title><style></style></head><body><h1id="dis1"></h1><h1id="dis2"></h1><scriptsrc="js.js"></script></body></html>
JavaScript
functionarrArg(arrArg1){varlocalArr=[];for(d=0;d<arrArg1.length;d++){localArr.push(arrArg1[d]*2);}returnlocalArr;}varmyVal=arrArg([2,3,4,5]);alert(myVal);/*Notes*We are passing arguments value in Array format.*/