Sunday, 2 July 2017
QUIZ SCRIPT
-------------------------------------------------------------------------------------------------------------
ReadMore:
http://www.multiwingspan.co.uk/javascript.php?page=quiz
http://www.flashbynight.com/tutes/mcqquiz/
SHUFFLE NUMBER CARD IN JAVA
http://materialdesignblog.com/10-material-design-cards-for-web-in-css-html/
https://www.w3schools.com/js/js_array_sort.asp
https://www.w3schools.com/js/tryit.asp?filename=tryjs_array_sort_reverse
http://jsfiddle.net/grainier/J4BuD/
Image to Word Matching Game js
https://www.pinterest.co.uk/pin/212372938648177172/
MAKE MATCHING ACTIVITY
https://www.quia.com/tutorials/activity_create
https://www.quia.com/mc/4.html
https://www.quia.com/cm/25645.html
https://www.quia.com/shared/science/
COUNTDOWN TIMER 1 TO 10 IN JAVASCRIPT
https://www.youtube.com/watch?v=iIwrMbERWI8--------------------------------------------------------------------------------------------------------------
CODE:
https://www.w3schools.com/js/tryit.asp?filename=tryjs_comparison
https://www.w3schools.com/js/tryit.asp?filename=tryjs_comparison_28
--------------------------------------------------------------------------------------------------------------
<!DOCTYPE html>
<!-- http://www.multiwingspan.co.uk/javascript.php?page=quiz -->
<!-- http://materialdesignblog.com/10-material-design-cards-for-web-in-css-html/ -->
<html>
<body>
<script type="text/javascript">
var answers = new Array("PARIS","MADRID")
var userAnswers = new Array
function checkAnswers() {
userAnswers[0] = document.myForm.QusestionOne.value
userAnswers[1] = document.myForm.QusestionTwo.value
var count = answers.length
var correct = 0
for (var i = 0;i<count;i++) {
if(userAnswers[i]==answers[i]) {
correct=correct+1
}
}
alert("You got " + correct)
}
</script>
<form name="myForm">
What is the capital of France? <input type="text" name="QusestionOne"><BR>
What is the capital of Spain? <input type="text" name="QusestionTwo"><BR>
<button onclick="checkAnswers()">Check your answers</button>
</form>
<!-- MY EXTRA CODE START -->
</br>
</br>
<style>
p,li{
list-style-type:Circle;
color: Black;
border-color: 1px solid Black;
}
FbGadgets{
background-color:HotPink;
}
</style>
<div id="BorderStyle" style="background-color:yellow;border:1px solid Black;">
<FbGadgets>Choose Your Answers In List:</FbGadgets>
<li>PARIS</li>
<li>MADRID</li>
</div>
</body>
</html>
============================================================================
<html>
<!-- https://www.youtube.com/watch?v=AmUrafV_wzQ -->
<!-- http://www.ikhtabirni.com/how-to-make-a-simple-quiz-using-html-javasript-and-css.html -->
<head>
<meta charset="utf-8" />
<title>Quiz</title>
</head>
<body>
<style>
#table_1 {
background-color: blue;
border: 4px solid black;
width: 420px;
height: 360px;
color: white;
text-align: center;
}
#center001 {
text-align: center;
}
</style>
<div id="table_1">
<h2>Quiz</h2>
<hr>
<div id="center001">Question: <text id="q001">0</text> Score: <text id="score001">0</text> Attempt: <text id="attempts">2</text></div>
<p id="question01"></p>
<p id="msg01"></p>
<br />
<br />
<div id="starter01">
<button onclick="begin001()" id="b001">Begin</button><br />
</div>
<p id="n001"></p>
<script>
var b = 0;
b++;
var c = 2;
c--;
var d = 0;
d++;
function begin001() {
document.getElementById("q001").innerHTML = d++;
document.getElementById("question01").innerHTML = "What is 5 + 5?" + "<br /><br /><br />" + "<button onclick=ans001() id=q1>10</button><br />" + "<button onclick=ans002() id=q2>8</button><br />" + "<button onclick=ans002() id=q3>25</button><br />";
document.getElementById("starter01").innerHTML = "";
}
function ans001() {
document.getElementById("score001").innerHTML = b++;
document.getElementById("question01").innerHTML = "Correct";
document.getElementById("starter01").innerHTML = "";
document.getElementById("n001").innerHTML = "<button onclick=nxt1()>Next</button><br />";
}
function ans002() {
document.getElementById("question01").innerHTML = "Incorrect";
document.getElementById("starter01").innerHTML = "";
document.getElementById("n001").innerHTML = "<button onclick=nxt1()>Next</button><br />";
document.getElementById("attempts").innerHTML = c--;
if (c < 0) {
document.getElementById("question01").innerHTML = "";
document.getElementById("msg01").innerHTML = "Sorry. You lost!";
document.getElementById("n001").innerHTML = "";
}
}
function nxt1() {
document.getElementById("question01").innerHTML = "What is 2 x 8?" + "<br /><br /><br />" + "<button onclick=ans004() id=q4>14</button><br />" + "<button onclick=ans004() id=q5>20</button><br />" + "<button onclick=ans003() id=q6>16</button><br />";
document.getElementById("n001").innerHTML = "";
document.getElementById("q001").innerHTML = d++;
}
function ans003() {
document.getElementById("score001").innerHTML = b++;
document.getElementById("question01").innerHTML = "Correct";
document.getElementById("starter01").innerHTML = "";
document.getElementById("n001").innerHTML = "<button onclick=nxt2()>Next</button><br />";
}
function ans004() {
document.getElementById("question01").innerHTML = "Incorrect";
document.getElementById("starter01").innerHTML = "";
document.getElementById("n001").innerHTML = "<button onclick=nxt2()>Next</button><br />";
document.getElementById("attempts").innerHTML = c--;
if (c < 0) {
document.getElementById("question01").innerHTML = "";
document.getElementById("msg01").innerHTML = "Sorry. You lost!";
document.getElementById("n001").innerHTML = "";
}
}
function nxt2() {
document.getElementById("question01").innerHTML = "";
document.getElementById("msg01").innerHTML = "End of Quiz.";
document.getElementById("n001").innerHTML = "";
}
</script>
</div>
</body>
</html>
------------------------------------------------------------------------------------------------------------
ADD REMOVE LISTENER JAVASCRIPT
-----------------------------------------------------------------------------------------------------------
<head>
<!-- http://help.dottoro.com/ljinxrmt.php -->
<script type="text/javascript">
function OnRedClick () {
alert ("A click event has occurred on the red button.");
}
function AddEventHandler () {
var redButton = document.getElementById ("redButton");
if (redButton.addEventListener) { // all browsers except IE before version 9
redButton.addEventListener ("click", OnRedClick, false);
}
else {
if (redButton.attachEvent) { // IE before version 9
redButton.attachEvent ('onclick', OnRedClick);
}
}
}
function RemoveEventHandler () {
var redButton = document.getElementById ("redButton");
if (redButton.removeEventListener) { // all browsers except IE before version 9
redButton.removeEventListener ("click", OnRedClick, false);
}
else {
if (redButton.detachEvent) { // IE before version 9
redButton.detachEvent ('onclick', OnRedClick);
}
}
}
</script>
</head>
<body>
Click on the red button when the 'click' event has a listener and when it does not.<br />
<button onclick="AddEventHandler ();">Add a 'click' event listener to the red button</button>
<button onclick="RemoveEventHandler ();">Remove the event listener</button>
<br /><br />
<button id="redButton" style="background-color:red">Red button</button>
</body>
----------------------------------------------------------------------------------------------------------
CSS CODE IN JAVASCRIPTADD REMOVE LISTENER JAVASCRIPT
-----------------------------------------------------------------------------------------------------------
<head>
<!-- http://help.dottoro.com/ljinxrmt.php -->
<script type="text/javascript">
function OnRedClick () {
alert ("A click event has occurred on the red button.");
}
function AddEventHandler () {
var redButton = document.getElementById ("redButton");
if (redButton.addEventListener) { // all browsers except IE before version 9
redButton.addEventListener ("click", OnRedClick, false);
}
else {
if (redButton.attachEvent) { // IE before version 9
redButton.attachEvent ('onclick', OnRedClick);
}
}
}
function RemoveEventHandler () {
var redButton = document.getElementById ("redButton");
if (redButton.removeEventListener) { // all browsers except IE before version 9
redButton.removeEventListener ("click", OnRedClick, false);
}
else {
if (redButton.detachEvent) { // IE before version 9
redButton.detachEvent ('onclick', OnRedClick);
}
}
}
</script>
</head>
<body>
Click on the red button when the 'click' event has a listener and when it does not.<br />
<button onclick="AddEventHandler ();">Add a 'click' event listener to the red button</button>
<button onclick="RemoveEventHandler ();">Remove the event listener</button>
<br /><br />
<button id="redButton" style="background-color:red">Red button</button>
</body>
----------------------------------------------------------------------------------------------------------
ADD CSS CLASS IN JAVASCRIPT
<style>
.CssClass{background-color:Gold;}
</style>
<button id="ButtonId">ADD CSS CLASS BUTTON</button>
<script>
ButtonId.onclick = function(){ButtonId.classList.add("CssClass")}
</script>
------------------------------------------------------------------------------------------------------------
SHOW DIV ONLY AFTER CLICK ON 3 BUTTONShttps://www.google.com/search?q=if+(btn1.onclick+%26%26+btn2.onclick)
------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>SHOW DIV ONLY AFTER CLICK ON 3 BUTTONS </title>
<!-- https://stackoverflow.com/questions/43866313/show-div-only-after-click-on-3-buttons -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
.theDiv{
background:red; height:10px; width:10px; display:none;
}
</style>
<script type="text/javascript">
window.onload=function(){
var countMyClicks = 0;
jQuery('.clickableOnce').on('click', function() {
countMyClicks++;
jQuery(this).prop('disabled', true);
if(countMyClicks==3){
jQuery('#theDiv').show();
}
});
}
</script>
</head>
<body>
<button class="clickableOnce">Btn 1</button>
<button class="clickableOnce">Btn 1</button>
<button class="clickableOnce">Btn 1</button>
<div class="theDiv" id="theDiv">
</div>
</body>
</html>
-------------------------------------------------------------------------------------------------------------
<style>
#myDiv {
border: thick solid blue;
}
</style>
<img id="myDiv" src="https://www.w3schools.com/tags/img_pulpit.jpg" width="304" height="228">
<br>
<button type="button" onclick="myFunction()">BUTTON</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.borderColor = "red";
}
</script>
-------------------------------------------------------------------------
RUN BELOW CODE MICROSOFT EDGE
NOT WORK IN GOOGLE CHROME
-------------------------------------------------------------------------
<html>
<!-- http://www.flashbynight.com/tutes/mcqquiz/ -->
<head>
<title>MCQ Quiz Sample</title>
<link href="http://www.flashbynight.com/tutes/mcqquiz/example/main.css"rel="stylesheet"type="text/css"/>
<meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script src="http://www.flashbynight.com/tutes/mcqquiz/example/jquery.js"></script>
<script src="http://www.flashbynight.com/tutes/mcqquiz/example/controller.js"></script>
</head>
<body>
<div id="topbar">HTML5 MCQ Quiz</div>
<div class="spacer"></div>
<div id="navContent">
<div id="game1"></div>
<div id="game2"></div>
</div>
</body>
</html>
--------------------------------------------------------------------------
CONDITION STATEMENT IN JAVA SCRIPT
--------------------------------------------------------------------------
<html>
<script type="text/javascript">
function myfunction(){
var first = document.getElementById("textbox1").value;
var second = document.getElementById("textbox2").value;
var answer =parseFloat(first)+parseFloat(second);
var textbox3 = document.getElementById('textbox3');
textbox3.value=answer;
if(first==second) {
alert('TEXT BOXES VALUE SAME');
}
else
alert('TEXT BOXES VALUE DIFFERENT');
}
</script>
<body>
<input type="text" name="textbox1" id="textbox1" /> + <input type="text" name="textbox2" id="textbox2" />
<input type="submit" name="button" id="button1" onclick="myfunction()" value="=" />
<br/>
Your answer is:--
<input type="text" name="textbox3" id="textbox3" readonly="true"/>
</body>
</html>
-----------------------------------------------------------------------
SIMPLE COUNTER IN JAVAFOR CHANGE BELOW CODE FOR ALERT COUNTER
document.getElementById("demo").innerHTML = ZERO;
//CHANGE DOCUMENT LINE CODE
alert(ZERO);
HOW CAN CHANGE P TAG
<p id="demo"></p>
<p id="demo">0</p>
OR USE THIS
function ReturnFunction() {
if (ZERO >= 10) {
ZERO = ZERO - 11 ;
}
};
----------------------------------------------------------------------
<button id="Btn1">Button</button>
<p id="demo"></p>
<script>
var ZERO = 0;
document.getElementById("demo").innerHTML = ZERO;
var Btn1 = document.getElementById("Btn1");
Btn1.onclick = function(){
ZERO++;// OR USE THIS ZERO = ZERO + 1
ReturnFunction();
document.getElementById("demo").innerHTML = ZERO;
}
function ReturnFunction() {
if(ZERO>10){
ZERO = 0;//OR USE THIS document.getElementById("demo").innerHTML = 0;
}
};
</script>
----------------------------------------------------------------------
<style>
#ButtonId{
width:165px;
height:42px;
font-size:30px;
font-weight:Bold;
color:Blue;
border-color:red;
border-width:5px;
background:url(https://images-na.ssl-images-amazon.com/images/G/02/rainier/nav/sc-unified._V360963816_.png) no-repeat;
}
</style>
<button id="ButtonId"></button>
<script>
var ZERO = 0;
document.getElementById("ButtonId").innerHTML = ZERO;
ButtonId.onclick = function(){
ZERO = ZERO + 1;
document.getElementById("ButtonId").innerHTML = ZERO;
}
</script>
----------------------------------------------------------------------
BUTTON HEIGHT WIDTH CONTROL WITH BUTTON
----------------------------------------------------------------------
<button id="ButtonId1">+</button>
<button id="ButtonId2">-</button>
<script>
ButtonId1.onclick = function(){
ButtonId1.style.width = (ButtonId1.clientWidth + 50) + "px";
}
ButtonId2.style.width ='900px'
ButtonId2.onclick = function(){
ButtonId2.style.width = (ButtonId2.clientWidth - 50) + "px";
}
</script>
-----------------------------------------------------------------------
<button id="Btn1">Button</button>
<p id="demo"></p>
<script>
var count = 0;
document.getElementById("demo").innerHTML = count;
var Btn1 = document.getElementById("Btn1");
Btn1.onclick = function(){
count++;
if(count>10){
count = 0;
}
document.getElementById("demo").innerHTML = count;
}
doCountdown = setInterval(countdown,1000);
</script>
----------------------------------------------------------------------
SIMPLE AUTO TIMER
----------------------------------------------------------------------
<p id="demo"></p>
<script>
var count = 0;
countdown=function(){
count++;
if(count>10){
count = 0;
}
document.getElementById("demo").innerHTML = count;
}
doCountdown = setInterval(countdown,1000);
</script>
-----------------------------------------------------------------------
<button onclick="FunctionNo2()">-1</button>
<button onclick="FunctionNo1()">+1</button>
<button onclick="FunctionNo0()">Reset</button>
<button id="demo"></button>
<style>
#demo{
width:173px;
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: auto;
padding: 1px;
border-width: 2px;
border-style: inset;
border-color: Black;
border-image: initial;
}
</style>
<script>
var ZERO = 0;
document.getElementById("demo").innerHTML = ZERO;
function FunctionNo0() {
ZERO = 0;
document.getElementById("demo").innerHTML = ZERO;
}
function FunctionNo1() {
ZERO += 1;
document.getElementById("demo").innerHTML = ZERO;
}
function FunctionNo2() {
ZERO -= 1;
document.getElementById("demo").innerHTML = ZERO;
}
</script>
-----------------------------------------------------------------------
SIMPLE COUNTER IN JAVA WITH CSS
-------------------------------------------------------------------------
SIMPLE COUNTER IN JAVA WITH CSS
-------------------------------------------------------------------------
<html>
<head>
<script>
var ZERO = 0;
function myFunction() {
ZERO += 1;
document.getElementById("TextBox1").innerHTML = ZERO;
}
</script>
<style>
#Div1,#TextBox1{
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body>
<p>Click the button to trigger a function.</p>
<div id="Div1"onclick="myFunction()">Click me</div>
<li id="TextBox1">0</li>
</body>
</html>
---------------------------------------------------------------------------------------------------------
SHUFFLE RANDOMISE ARRAY
https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
https://jsfiddle.net/fmjL1eyL/
https://jsfiddle.net/fmjL1eyL/
----------------------------------------------------------------------------------------------------------
<html>
<head>
<script type='text/javascript'>
//<![CDATA[
window.onload=function(){
Array.prototype.shuffled = function() {
return this.map(function(n){ return [Math.random(), n] })
.sort().map(function(n){ return n[1] });
}
var arr = ["My", "ex", "man", "brought", "his", "new",
"girlfriend", "she's", "like", "Oh", "my",
"God", "I'm", "just", "gonna", "shake"];
function shake() {
document.getElementById("shuffled").innerHTML =
"<ul><li>" + arr.shuffled().join('\n<li>') + "</ul>";
}
document.getElementById("shaker").onclick = shake;
}//]]>
</script>
</head>
<body>
<div id="shuffled"></div>
<input type="Button" value="Shake" id="shaker" />
</body>
</html>
----------------------------------------------------------------------------------------------------------
CODE : 2
----------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Randomize array</title>
<script type='text/javascript'>
//<![CDATA[
window.onload=function(){
function shuffleArray(array){
var temp = [];
var len=array.length;
while(len){
temp.push(array.splice(Math.floor(Math.random()*array.length),1)[0]);
len--;
}
return temp;
}
alert("Here >>> "+shuffleArray([4,2,3,5,8,1,0]));
}//]]>
</script>
</head>
<body>
</body>
</html>
----------------------------------------------------------------------------------------------------------
ADD <P> TAG document.getElementById FUNCTION IN ALERT ABOVE
CODE : 2
ADD NEW YELLOW LINES
document.getElementById("demo").innerHTML = temp;
<p id="demo">0</p>
IN BELOW CODE WE CAN ALSO CHANGE ALERT LINE WITHDOCUMENT.WRITE
alert("Here >>> "+shuffleArray([4,2,3,5,8,1,0]));
document.write("Here >>> "+shuffleArray([4,2,3,5,8,1,0]));
CREATE ELEMENT IN JAVASCRIPT
<!-- https://www.youtube.com/watch?v=VW8kNAous88
-->
<script>
let newElement = document.createElement('div');
console.log(newElement); //SHOW RESULT IN
GOOGLE CONSOLE PANEL
</script>
----------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Randomize array</title>
<script type='text/javascript'>
//<![CDATA[
window.onload=function(){
function shuffleArray(array){
var temp = [];
var len=array.length;
while(len){
temp.push(array.splice(Math.floor(Math.random()*array.length),1)[0]);
len--;
}
document.getElementById("demo").innerHTML = temp;
return temp;
}
alert("Here >>> "+shuffleArray([4,2,3,5,8,1,0]));
}//]]>
</script>
</head>
<body>
<p id="demo">0</p>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------
FLASH RANDOM ARRAY CODE CHANGE INTO JAVA SCRIPT
https://flashcollege.blogspot.co.uk/2016/03/trace-array-in-text-box-as2-as3.htmlhttps://stackoverflow.com/questions/11980657/as3-random-array-randomize-array-actionscript-3
-----------------------------------------------------------------------------------------------------------------------
// Array to Randomize
var firstArray:Array = ["One","Two","Three","Four","Five","six","seven","eight","nine","ten"];
trace(firstArray); // Prints in order
var newArray:Array = new Array();
function randomizeArray(array:Array):Array
{
var newArray:Array = new Array();
while (array.length > 0)
{
newArray.push(array.splice(Math.floor(Math.random()*array.length), 1));
}
return newArray;
}
var randomArray:Array = randomizeArray(firstArray);
trace(randomArray); // Prints out randomized :)
ABOVE FLASH CODE INTO JAVA SCRIPT
----------------------------------------------------------------------------------------------------------------------
<html>
<body>
<script>
var firstArray = ["One","Two","Three","Four","Five","six","seven","eight","nine","ten"];
var newArray= new Array();
function randomizeArray(array){
var newArray = new Array();
while (array.length > 0){
newArray.push(array.splice(Math.floor(Math.random()*array.length), 1));
}
return newArray;
}
var randomArray = randomizeArray(firstArray);
document.write(randomArray);
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------
CHANGE CONSOLE LOG CODE INTO DOCUMENT GET ELEMENT CODE
READ MORE:
http://www.peachpit.com/articles/article.aspx?p=100577&seqNum=382
BOOLEAN COUNTER IN JAVASCRIPT
READ MORE:
http://www.peachpit.com/articles/article.aspx?p=100577&seqNum=382
BOOLEAN COUNTER IN JAVASCRIPT
----------------------------------------------------------------------------------------------------------------------
BOOLEAN CHANGE INTO NUMBER
var myBoolean:Boolean = true; var myInt:int = int(myBoolean);trace(myINT); // output: 1
var myBoolean:Boolean = false;var myInt:int = int(myBoolean);trace(myINT); // output: 0
var myNumber= Number(myBoolean);
document.write(myNumber);
var myBoolean:Boolean = true; var myInt:int = int(myBoolean);trace(myINT); // output: 1
var myBoolean:Boolean = false;var myInt:int = int(myBoolean);trace(myINT); // output: 0
---------------------------------------------------------------------------------------------------------------
<button id="Btn1">CounterStartAfterSecondClick</button>
<!--
https://stackoverflow.com/questions/32688621/how-to-get-alert-message-on-second-click-of-a-button
-->
<script>
var Boolean=false;
var ZERO = 0;
Btn1.onclick=function(){
if(Boolean==true){
ZERO += 1;
Btn1.innerHTML = ZERO;
}
else{
Boolean=true;
}
}
</script>
--------------------------------------------------------------------------
<button id="Btn1">Btn1</button>
<script>
var previousTarget=null;
Btn1.onclick = function(){
if(this===previousTarget){
alert("You've clicked this element twice.");
}
previousTarget=this;
return false;
}
</script>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<button id="Btn1">Btn1</button>
<script>
var previousTarget=null;
Btn1.onclick = function(){
if(this===previousTarget){
alert("You've clicked this element twice.");
}
previousTarget=this;
return false;
}
</script>
<script>
var myBoolean = true;var myNumber= Number(myBoolean);
document.write(myNumber);
</script>
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
<button id="Btn1">Btn1</button><script>var Boolean=false;Btn1.onclick=function(){if(Boolean){Btn1.innerHTML=Boolean;}else{Boolean=true;}}</script>
-----------------------------------------------------------------------------------------------------------------
console.log(arr) <----> document.getElementById("demo").innerHTML = arr;
ReadMore:
console.log(arr); <---->
document.getElementById("demo").innerHTML = arr;
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
RANDOM JAVA SCRIPT ARRAY CODE:
DOCUMENT WRITE IN
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
RANDOM JAVA SCRIPT ARRAY CODE:
DOCUMENT WRITE IN
----------------------------------------------------------------------------------------------------------------------
<html>
<!-- https://stackoverflow.com/questions/1516695/js-math-random-for-array -->
<body>
<script>
var Array = new Array('a', 'b', 'c', 'd', 'e');
document.write("Test "+ Array[Math.floor(Math.random() * ((Array.length - 1) - 0 + 1))]);
</script>
</body>
</html>
-------------------------------------------------------------------------------------------------------------
<html>
<!-- https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array -->
<body>
<p id="demo"></p>
<script>
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
// Used like so
var arr = [2, 11, 37, 42];
arr = shuffle(arr);
document.getElementById("demo").innerHTML = arr;
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------------
shuffle array javascripthttps://www.google.co.uk/search?q=shuffle+array+javascript
https://www.kirupa.com/html5/shuffling_array_js.htm
----------------------------------------------------------------------------------------------------------
<html>
<!-- https://www.kirupa.com/html5/shuffling_array_js.htm -->
<head>
<title>Randomize array</title>
<script type='text/javascript'>
//<![CDATA[
Array.prototype.shuffle = function() {
var input = this;
for (var i = input.length-1; i >=0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
}
return input;
}
var tempArray = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
tempArray.shuffle();
// and the result is...
alert(tempArray);
//]]>
</script>
</head>
<body>
</body>
</html>
-----------------------------------------------------------------------
SHUFFLE WORD BATMAN IN JAVA SCRIPT
-------------------------------------------------------------------------
SHUFFLE WORD BATMAN IN JAVA SCRIPT
-------------------------------------------------------------------------
<html>
<body>
<script type='text/javascript'>
//<![CDATA[
window.onload=function(){
function shuffelWord(word) {
var shuffledWord = '';
var charIndex = 0;
word = word.split('');
while (word.length > 0) {
charIndex = word.length * Math.random() << 0;
shuffledWord += word[charIndex];
word.splice(charIndex, 1);
}
return shuffledWord;
}
document.querySelector('.word').innerHTML = shuffelWord('BATMAN');
}
//]]>
</script>
<p class="word"></p>
</body>
</html>
----------------------------------------------------------------------
http://jsfiddle.net/trevordowdle/E4qzS/11/
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
<html>
<head>
<script type='text/javascript' src='https://cdn.css-tricks.com/wp-content/themes/CSS-Tricks-16/js/libs/jquery-3.1.1.min.js'></script>
<script type="text/javascript" charset="utf-8">
var testArray = [1,2,3,4,5];
Shuffle(testArray);
function Shuffle(o) {
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
$(function() {
for (var i=0;i<testArray.length;i++) {
$("#dump").append(testArray[i]);
}
});
</script>
<h3>Technique #1</h3>
<div id="dump" style="background: #ccc; padding: 5px;"></div>
</body>
</html>
------------------------------------------------------------------------------------------------
HELLO IN JAVA SCRIPT WITHOUT FUNCTION
WE ALSO CHANGE TEXT AREA IN TO P TAG
<p id="demo"></p>
<script>
document.getElementById("HtmlDivId").innerHTML = "HELLO";
</script>
<div id="HtmlDivId"></div>
-------------------------------------------------------------------------------------------
<!-- http://jsfiddle.net/mQMVc/ -->
<!-- https://stackoverflow.com/questions/4879066/what-innerhtml-is-doing-in-javascript -->
<h1>DIV TAG IN JAVASCRIPT</h1>
<div id="demo"></div>
<script type='text/javascript'>
document.getElementById('demo').innerHTML = "<div>Hello World!</div>";
</script>
----------------------------------------------------------------------------
SAY HELLO INPUT BOX<input id="TextBox">
<button onclick="getElementById('TextBox').value='HELLO'">BUTTON</button>
SAY HELLO INPUT BOX WITH JAVA
<input id="TextBox">
<button id="BUTTON">BUTTON</button>
<script>
BUTTON.onclick = function(){
TextBox.value = "HELLO";
};
</script>
-------------------------------------------------------------------------------------------------------------------
SAY HELLO IN HTMLHow to get onclick button to show text in input box
<!-- https://stackoverflow.com/questions/19578542/how-to-get-onclick-button-to-show-text-in-input-box -->
<!-- https://codepen.io/anon/pen/zCJcp -->
<!-- https://www.w3schools.com/jsref/event_onclick.asp -->
<!-- https://www.w3schools.com/jsref/event_onclick.asp -->
<!-- SAY HELLO IN HTML -->
The Box:<input type="text" id="thebox" value="" size=10>
<br><input type="button" value="What's in the booooox?" onclick="document.getElementById('thebox').value='head of gwyneth paltrow';">
//OR USE THIS CODE
<button onclick="getElementById('demo').innerHTML='HELLO'">BUTTON</button>
<p id="demo"></p>
--------------------------------------------------------------------------------------------------------------------
HELLO FUNCTION IN JAVA SCRIPT
<!--AFTER BODY TAG HTML CODE THEN USE JAVASCRIPT CODE-->
WE CANT USE AFTER BODY TAG JAVA SCRIPT CODE THEN HTML CODE
<div id="demo"></div>
<script>
demo.innerHTML = "SAY HELLO";
</script>
OR USE THIS CODE
<div id="demo"></div>
<script>
var x = "SAY HELLO";
document.getElementById("demo").innerHTML =x
</script>
-------------------------------------------------------------------------------------------------------------------
<html>
<!-- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_function -->
<body>
<p id="demo"></p>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World!";
}
myFunction();
</script>
</body>
</html>
==============================================================================
SAY HELLO WITH DOCUMENT WRITE
==============================================================================
<html>
<body>
<script>
function myFunction(){
var x = "SAY HELLO"
document.write(x);
}
myFunction();
</script>
</body>
</html>
SAY HELLO WITH DOCUMENT GET ELEMENT BY ID
==============================================================================
<html>
<p id="demo"></p>
<body>
<script>
function myFunction() {
var x = "SAY HELLO"
document.getElementById("demo").innerHTML = x;
}
myFunction();
</script>
</body>
</html>
=============================================================================
SAY HELLO IN ARRAY FUNCTION
BECAUSE JAVA SCRIPT WORK WITH ID
HOW TO TO SHORT INNER HTML LINE
document.getElementById("demo").innerHTML = x;
OR USE THIS SHORT LINE
BECAUSE JAVA SCRIPT WORK WITH ID
HOW TO TO SHORT INNER HTML LINE
document.getElementById("demo").innerHTML = x;
OR USE THIS SHORT LINE
demo.innerHTML = x;
=============================================================================
<p id="demo"></p>
<script>
function myFunction(){
//ARRAY LINE INSIDE FUNCTION
var x = ["SAY HELLO","SAY HELLO"];
//JAVA DOCUMENT LINE INSIDE FUNCTION
document.getElementById("demo").innerHTML = x;
}
myFunction();
</script>
=============================================================================
=============================================================================
<p id="demo"></p>
<script>
//ARRAY LINE OUTSIDE FUNCTION
var x = ["SAY HELLO","SAY HELLO"];
function myFunction(){
//JAVA DOCUMENT LINE INSIDE FUNCTION
document.getElementById("demo").innerHTML = x;
}
myFunction();
</script>
=============================================================================
<p id="demo"></p>
<script>
var x = "SAY HELLO"
function myFunction(){
return x;
}
myFunction();
document.getElementById("demo").innerHTML = myFunction(x);
</script>
==============================================================================
==============================================================================
var x = "SAY HELLO";
function myFunction(x){
return x;
}
myFunction(x);
===============================================================================
<body>
<script type="text/javascript">
var x = "SAY HELLO"
myFunction = function(MY){
return MY;
};
document.write(myFunction(x));
</script>
</body>
============================================================================
==========================================================================================================================================================
<body>
<div id ="demo" </div>
<script type="text/javascript">
var x = "SAY HELLO"
function myFunction(MY){
return MY;
};
document.getElementById("demo").innerHTML = myFunction(x);
</script>
</body>
<p id="demo"></p>
<script>
//ARRAY LINE OUTSIDE FUNCTION
var x = ["SAY HELLO","SAY HELLO"];
function myFunction(){
//ONLY RETURN LINE INSIDE FUNCTION
return x;
}
//JAVA DOCUMENT LINE OUTSIDE FUNCTION
document.getElementById("demo").innerHTML = myFunction(x);
</script>
SAY HELLO WITH ALERT BOX
===============================================================================
<html>
<body>
<script>
function myFunction() {
var x = "SAY HELLO"
alert(x)
}
myFunction();
</script>
</body>
</html>
=============================================================================
<html>
<!-- https://www.w3schools.com/js/tryit.asp?filename=tryjs_variables -->
<body>
<p id="demo"></p>
<script>
function myFunction(){
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo").innerHTML = z;
}
myFunction();
</script>
</body>
</html>
==========================================================================
<html>
<body>
<p id="demo"></p>
<script>
function myFunction(p1, p2) {
return p1 * p2;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
</script>
</body>
</html>
OR CHANHGE ABOVE CODE
<html>
<!-- https://www.w3schools.com/js/tryit.asp?filename=tryjs_functions -->
<p id="demo"></p>
<body>
<script>
function myFunction() {
var p1 = 4;
var p2 = 3;
var x = p1 * p2;
alert(x)
document.getElementById("demo").innerHTML = x ;
}
myFunction();
</script>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------
HOW TO REMOVE BODY ON LOAD FUNCTION
<!--AFTER BODY TAG HTML CODE THEN USE JAVASCRIPT CODE-->
WE CANT USE AFTER BODY TAG JAVA SCRIPT CODE THEN HTML CODE
<body onLoad = "myFunction()"> <-----------> <body>
USE SAME WORDS IN HTML AND JAVA SCRIPT
<img id="SameWord1">
<script>
SameWord1.src="https://www.w3schools.com/tags/smiley.gif";
</script>
<html>
<head></head>
<body>
<!--AFTER BODY TAG HTML CODE THEN USE JAVASCRIPT CODE-->
<img id="myImg">
<script type='text/javascript'>
function myFunction(){
x = "http://img5.uploadhouse.com/fileuploads/17699/176992640c06707c66a5c0b08a2549c69745dc2c.png",
document.getElementById("myImg").src= x;
}
myFunction();
</script>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------
<html>
<TITLE>HELLO IN JAVA SCRIPT</TITLE>
<body>
<textarea id="demo"></textarea>
<button id="ShowTextInButton"></button>
<script>
document.getElementById("demo").innerHTML = "JAVA SCRIPT HELLO TEXT IN TEXT AREA";
document.querySelector("textarea").style.backgroundColor = "Green"; //CHANGE CSS COLOR IN TEXT AREA
document.getElementById("ShowTextInButton").innerHTML = "JAVA SCRIPT HELLO TEXT IN BUTTON";
document.querySelector("button").style.backgroundColor = "Red"; //BUTTON CHANGE CSS COLOR
alert(document.getElementById("demo").innerHTML);
document.write(document.getElementById("demo").innerHTML);
</script>
</body>
</html>
------------------------------------------------------------------------------------------------------
WRITE ALERT LINE INSIDE FUNCTION
alert("I am an alert box!");
https://www.w3schools.com/js/tryit.asp?filename=tryjs_alert
------------------------------------------------------------------------------------------------
<html>
<h2>JavaScript Alert With Button</h2>
<body>
<script type='text/javascript'>
function myFunction(){
alert("I am an alert box!");
}
</script>
<button onclick="myFunction()">Try it</button>
</body>
</html>
------------------------------------------------------------------------------------------------
<html>
<h2>JavaScript Alert Without Button</h2>
<body>
<script type='text/javascript'>
function myFunction(){
return alert;
}
alert("I am an alert box!");
</script>
</body>
</html>
----------------------------------------------------------------
ALERTBOX WITH VARIABLE
-----------------------------------------------------------------
<html>
<h2>JavaScript Alert Without Button</h2>
<body>
<script type='text/javascript'>
var AlertBox = "I Am An AlertBox!";
function myFunction(){
return alert;
}
alert(AlertBox);
</script>
</body>
</html>
<html>
<h2>JavaScript Alert With VARIABLE</h2>
<body>
<script type='text/javascript'>
var AlertBox = "I Am An AlertBox!";
function myFunction(){
alert(AlertBox);
}
</script>
<button onclick="myFunction()">FunctionRunWithButton</button>
</body>
</html>
----------------------------------------------------------------------------------------------
JAVA SCRIPT ALERT WITH DOCUMENT ID P TAG
document.getElementById("demo").innerHTML = AlertBox ;
---------------------------------------------------------------
<html>
<h2>JAVA SCRIPT ALERT WITH DOCUMENT ID P TAG </h2>
<head>
<script>
var AlertBox = "I Am An AlertBox!";
function myFunction() {
alert(AlertBox);
document.getElementById("demo").innerHTML = AlertBox ;
}
</script>
</head>
<body>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</body>
</html>
FOLLOW STEPS:
ADD P TAG BEFORE JAVA CODE WHEN WE DONOT USE FUNCTION NAME
<html>
<!-- https://www.w3schools.com/js/tryit.asp?filename=tryjs_variables-->
<h2>JavaScript Variables WITHOUT FUNCTION NAME</h2>
<body>
<!-- ADD P TAG BEFORE JAVA CODE WHEN WE DONOT USE FUNCTION NAME-->
<p id="demo"></p>
<script>
var AlertBox = "I Am An AlertBox!";
document.getElementById("demo").innerHTML = AlertBox;
</script>
</body>
</html>
BUTTON VALUE AND BUTTON ID TRACE IN JAVA SCRIPT
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_button_value
-------------------------------------------------------------------------------------------------------
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_button_value
-------------------------------------------------------------------------------------------------------
<html>
<!-- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_button_value -->
<body>
<script>
function FunctionNo1() {
var Variable1 = document.getElementById("Btn1").value;
document.getElementById("TextBox1ForButtonValue").innerHTML = Variable1;
alert(Variable1)
}
</script>
<button id="Btn1" value="1" onclick="FunctionNo1()">CLICK AND FIND BUTTON VALUE </button>
<p id="TextBox1ForButtonValue"></p>
<script>
function FunctionNo2() {
var Variable1 = document.getElementById("Btn2").id;
document.getElementById("TextBox1ForButtonValue").innerHTML = Variable1;
alert(Variable1)
}
</script>
<button id="Btn2" value="1" onclick="FunctionNo2()">CLICK AND FIND BUTTON ID </button>
<p id="TextBox1ForButtonValue"></p>
</body>
</html>
IMAGE SHOW HIDE WITH JAVA SCRIPT
https://stackoverflow.com/questions/15318357/show-hide-image-with-javascript
<style>
#ImageId{
width:100px;
height:100px;
border-style:Double;
border-color:Blue;
background-color:LightGreen;
/*https://www.w3schools.com/w3css/w3css_colors.asp*/
}
</style>
<img src ="smiley.gif" id="ImageId"></img>
<script>
ImageId.onclick = function(){
document.getElementById('ImageId').style.visibility='hidden';
}
</script>
--------------------------------------------------------------------------------------------------------------
BUTTON ARRAY VISIBILITY HIDDEN
OR USE THIS LINE
var btnArray = [btn1,btn2];
---------------------------------------------------------------------------------------------------------------
<button id="btn1">#1</button>
<button id="btn2">#2</button>
<script>
var btnArray = new Array(btn1,btn2);
btnArray[0].style.visibility = "hidden";
btnArray[1].style.visibility = "hidden";
</script>
---------------------------------------------------------------------------------------------------------------
for (var i = 0; i < 2; i++){
OR USE THIS LOOP LINE I IS EQUAL TO ZERO AND I IS SHORTER THAN 2 i<2
---------------------------------------------------------------------------
<button id="btn1">#1</button>
<button id="btn2">#2</button>
<script>
var btnArray = [btn1,btn2];
//REMOVE BY FOR LOOP
for (var i = 0; i < btnArray.length; i++){
btnArray[i].style.visibility =
"hidden";
}
</script>
----------------------------------------------------------------------------------------------------------------
<html>
<!-- https://stackoverflow.com/questions/15318357/show-hide-image-with-javascript -->
<style>
#demo{
position:absolute;
visibility:hidden;
top:50px;left:50px;
}
</style>
<body>
<img src ="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBmtzUWLAKgAgfuhUUFh-KvZ4Ub1AGWSAJMkDkrojYX0Qhq2vtbL0QEbt6u2GJg0TgzvuW7qarxJ9UCAiRl7xQvLHfCtoLg03MEaA2UsmxCO5PK_ygbNbpXFkRgo6LNOoafePAJBuACRba/s1600/image6.gif" id="demo">
<script type="text/javascript">
function FunctionShow() {
document.getElementById('demo').style.visibility='visible';
}
function FunctionHide() {
document.getElementById('demo').style.visibility='hidden';
}
</script>
<input type="button" onclick="FunctionShow()" value="SHOW">
<input type="button" onclick="FunctionHide()" value="HIDE">
</body>
</html>
-------------------------------------------------------------------------
<html>
<body>
<script type='text/javascript'>
//<![CDATA[
function shuffleArray ( array ) {
var counter = array.length, temp, index;
// While there are elements in the array
while ( counter > 0 ) {
// Pick a random index
index = Math.floor( Math.random() * counter );
// Decrease counter by 1
counter--;
// And swap the last element with it
temp = array[ counter ];
array[ counter ] = array[ index ];
array[ index ] = temp;
}
return array;
}
var originalArray = [ 'a', 'b', 'c', 'd' ];
var shuffledArray = shuffleArray( originalArray );
alert( shuffledArray );
//]]>
</script>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------
SHOW HIDE IMAGE
http://jsfiddle.net/ipsjolly/k4WWj/
we can change widow and click me
we can change widow and click me
window.onload=function(){
clickme.onclick
= function(){
-----------------------------------------------------------------------------------------------------------------
<html>
<!-- http://jsfiddle.net/ipsjolly/k4WWj/ -->
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.0b1.js"></script>
<style type="text/css">
#book{
display:none;
}
</style>
<title> by ipsjolly</title>
<script type='text/javascript'>
//<![CDATA[
$(window).load(function(){
$('#clickme').click(function() {
$('#book').toggle('slow', function() {
// Animation complete.
alert( $('#book').is(":visible"));
});
});
});
//]]>
</script>
</head>
<body>
<button id="clickme">
Click here
<img id="book" src="http://www.chromefusion.com/wp-content/uploads/2012/06/chrome-logo.jpg" alt="" />
</button>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------
BUTTON ADD EVENT LISTENER IN JAVA SCRIPT
we can also change lines like
(Btn1).addEventListener("click", function(){
document.getElementById("Btn1").addEventListener("click", function(){
<img id="Btn1" src="https://www.w3schools.com/Jsref/smiley.gif">
-----------------------------------------------------------------------------------------------------------------
<html>
<head>
<style></style>
</head>
<!-- https://www.w3schools.com/Jsref/met_element_addeventlistener.asp -->
<body>
<button id="Btn1">Button</button>
<script>
Btn1.addEventListener("click", function(){
alert("Hello World")
})
</script>
</body>
</html>
----------------------------------------------------------------------
TRACE
1)BUTTON ID,
2)BUTTON HTML ENCLOSED HTML CONTENT BLACK TEXT
3)BUTTON NAME
4)BUTTON VALUE
----------------------------------------------------------------------
<button id="ButtonId" name="ButtonName"
value="1">Button Html Content Element</button>
<div id="DivId1"></div>
<div id="DivId2"></div>
<div id="DivId3"></div>
<div id="DivId4"></div>
<div id="DivId4"></div>
<script>
ButtonId.onclick = function(){
DivId1.innerHTML = this.id;
DivId2.innerHTML = this.innerHTML;
DivId3.innerHTML = this.name;
DivId4.innerHTML = this.value;
};
</script>
----------------------------------------------------------------------
<button id="AddEventListener">AddEventListener</button>
<script>
AddEventListener.addEventListener("click",WindowOpen,true);
function WindowOpen(){
window.open("https://www.w3schools.com/jsref/met_element_addeventlistener.asp");
}
</script>
----------------------------------------------------------------------
<button id="AddEventListener">AddEventListener</button>
<script>
AddEventListener.addEventListener("click", function(){
window.open("https://www.w3schools.com/jsref/met_element_addeventlistener.asp");
});
</script>
======================================================================
SAY HELLO WITH JAVA AND DIV CLASS WITH DOCUMENT QUERY SELECTOR
=======================================================================
<html>
<!-- https://www.w3schools.com/jsref/met_document_queryselector.asp -->
<body>
<div class="demo"></div>
<script>
document.querySelector(".demo").innerHTML = "Hello World!";
</script>
</body>
</html>
=========================================================================
<body>
<button id="Btn1">Button</button>
<p id="TEXTBOX1"></p>
<script>
Btn1.addEventListener("click",FN1,true);
function FN1(){
alert("Hello World")
Btn1.innerHTML ="Hello World"
TEXTBOX1.innerHTML ="Hello World"
}
</script>
</body>
==========================================================================
<html>
<!-- http://idratherbewriting.com/events-and-listeners-javascript/ -->
<body>
<button id="Btn1">Button</button>
<script>
var Btn1 = document.getElementById("Btn1");
Btn1.onclick = function(){
alert("Hello World")
};
</script>
</body>
</html>
==================================================================
SAY HELLO WITH BUTTON ID AND DIV ID
===========================================================================
<html>
<!--CODE LOOKS LIKE AS2 https://en.wikibooks.org/wiki/Introduction_to_ActionScript_2.0/Event_Handling -->
<body>
<button id="ButtonId">Button</button>
<div id="DivId">SAY HELLO WITH ButtonId AND DivId </div>
<script>
ButtonId.onclick = function(){
alert("Hello World")
DivId.innerHTML = "SAY HELLO";
};
</script>
</body>
</html>
<style>
#ImageId{
width:100px;
height:96px;
float:left;
border-style:Double;
border-color:Blue;
background-color:LightGreen;
}
#demo{
width:auto;
height:100px;
float:left;
}
</style>
<button id="demo">BUTTON SHOW IMAGE SRC </button>
<img src ="https://www.w3schools.com/html/smiley.gif" id="ImageId"></img>
<script>
ImageId.onclick = function(){
var x = document.getElementById("ImageId").src;
document.getElementById("demo").innerHTML = x;
}
</script>
---------------------------------------------------------------------------------
SIMPLE MATCHING GAME JAVASCRIPT
---------------------------------------------------------------------------------
<html>
<!-- https://codereview.stackexchange.com/questions/172417/simple-memory-game-in-javascript -->
<head>
<title>Memory Game</title>
<style>
div#TextBox1 {
background-color: coral;
color: blueviolet;
text-align: center;
font:20px bold;
display: block;
}
.matched {
background:Green;
}
</style>
</head>
<body>
<div id="TextBox1"></div>
<button id="0">A</button>
<button id="0">APPLE</button>
<button id="1">B</button>
<button id="1">BALL</button>
<script>
var firstClickedTile;
var secondClickedTile;
for (var i = 0; i < document.querySelectorAll("button").length; i++) {
document.querySelectorAll("button")[i].addEventListener('click', MatchingFunction,true);
}
function MatchingFunction(event) {
if (!firstClickedTile){
firstClickedTile = event.target;
}
else if (firstClickedTile!== event.target) {
secondClickedTile = event.target;
TextBox1.innerHTML = "TryAgain";
if (firstClickedTile.id == secondClickedTile.id) {
firstClickedTile.classList.add("matched");
secondClickedTile.classList.add("matched");
TextBox1.innerHTML = "Good Job";
}
console.log(event.target.id); //CONSOLE ID
function setTimeout(){
firstClickedTile = undefined;
}
setTimeout(400);
}
}
</script>
</body>
</html>
------------------------------------------------------------------------------------------------------------
USE HTML CLASS IN JAVA SCRIPT
------------------------------------------------------------------------------------------------------------
<img class="swatch-option image" src="https://www.w3schools.com/jsref/compman.gif" width="107" height="98">
<script>
document.querySelector(".swatch-option.image").height = "70";
</script>
-----------------------------------------------------------------------------------------------------------------
https://stackoverflow.com/questions/4711499/help-with-creating-a-random-placement-of-text
-----------------------------------------------------------------------------------------------------------------
https://stackoverflow.com/questions/4711499/help-with-creating-a-random-placement-of-text
-----------------------------------------------------------------------------------------------------------------
I want the the text to randomly appear left, center, or right within the text box.
Here is the test page: www.creativewritingstudio.com/Home_2.html
Below is the script I am using:
<font face="helvetica" color="1b1b1b" size="5px" repeat>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Random Text w/ jQuery</title>
<style type="text/css">
#text-box {
padding: 4px;
width: 602px;
}
#text-content {
color: #1b1b1b;
text-align : center;
}
#text-reload {
display: block;
margin-top: 4px;
text-align: right;
outline: none;
}
</style>
</head>
<body>
<div id="text-box">
<div id="text-content"></div> <!-- random text goes in ther -->
</div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready( function() {
var textArray = [
'Flow',
'Precision',
'Voice',
'Imagery',
'Pace',
'Unity',
'Word Choice',
'Rhythm',
'Inspiration',
'Balance',
'Clarity',
'Simplicity',
'Revision',
'Discipline',
'Fundamentals',
'Dedication',
'Practice',
];
$('#text-content').loadText( textArray, 5500 ); // ( array, interval )
});
// custom jquery plugin loadText()
$.fn.loadText = function( textArray, interval ) {
return this.each( function() {
var obj = $(this);
obj.fadeOut( 'slow', function() {
obj.empty().html( random_array( textArray ) );
obj.fadeIn( 'slow' );
});
timeOut = setTimeout( function(){ obj.loadText( textArray, interval )}, interval );
// reload random text (if not animated) -- entirely optional, can be removed, along with the reload link above (<a href="javascript:;" id="text-reload"><em>randomize</em></a>)
$("#text-reload").click( function(){
if( !obj.is(':animated') ) { clearTimeout( timeOut ); obj.loadText( textArray, interval );} // animation check prevents "too much recursion" error in jQuery
});
});
}
//public function
function random_array( aArray ) {
var rand = Math.floor( Math.random() * aArray.length + aArray.length );
var randArray = aArray[ rand - aArray.length ];
return randArray;
}
</script>
</html>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment