This question relates to JavaScript.
Could you please show me how to get my code below working. Please keep it simple.
The code has a green square image. When it is clicked the function generates a random number from 1-3. If the number generated is '1' then the green square is replaced by a picture of a tree. Please keep it as simple as possible because I am new to coding. Thanks.
<html>
<head>
<title></title>
<script>
var randNum;
var but;
var but1;
//var imageArray =
["greenSq1","greenSq2","greenSq3"];
/**
* This function generates a random
number between 1-3
*/
function randFun1(){
randNum =
Math.floor(Math.random()*10);
randNum =
Math.round(randNum/3);
if(randNum !=0){
rNum = randNum;
}
if(rNum == 1){
document.getElementById("greenSq1").src = "tree";
}
}
</script>
</head>
<body>
<img id="greenSq1"
src="greenSquare.png" onClick="randFun1"
style="width:100px;height:100px;visibility:visible"/>
<img id="tree" src="tree.jpg"
style="width:100px;height:100px;visibility:hidden"/>
</body>
</html>
If you have any doubts, please give me comment...
<html>
<head>
<title></title>
</head>
<body>
<img id="greenSq1" src="greenSquare.png" onClick="randFun1()" style="width:100px;height:100px;" />
</body>
<script type="text/javascript">
var randNum;
var but;
var but1;
//var imageArray = ["greenSq1","greenSq2","greenSq3"];
/**
* This function generates a random number between 1-3
*/
function randFun1() {
randNum = Math.floor(Math.random() * 10);
randNum = (randNum % 3) + 1;
if (randNum == 1) {
document.getElementById("greenSq1").src = "tree.png";
} else {
document.getElementById("greenSq1").src = "greenSquare.png";
}
}
</script>
</html>
This question relates to JavaScript. Could you please show me how to get my code below...
This question relates to Javascript. Could you please show me why my code is not working? I want to create 2 text boxes and have the user enter something into both of them. If the text entered into both boxes is identical the a green message is made visible. If the boxes are different a red message is made visable. Please keep it simple because I am new to javascript. <html> <head> <title></title> <script>...
This question relates to Javascript. Could you please show me why my code is not working? I want to create 2 text boxes and have the user enter something into both of them. If the text entered into both boxes is identical the a green message is made visible. If the boxes are different a red message is made visable. Please keep it simple because I am new to javascript. <html> <head> <title></title> <script>...
Could you please help me write a Javascript code that will show a smiley face picture when I click the button. The picture should not display until the button is pressed. Here is my attempt at the code. It does not work. Please keep the code as simple as you can as I am new to coding. Please also use the <div> tag if possible, onclick and use the getElementById. Thank you <html> <body> <img id="exampleImage" src="smileyFace.png" /> <button onclick="pushButton()">Try...
could you please show me what I am doing wrong in the Javascript code below. <html> <head> <meta charset="UTF-8"> <title></title> <style> #mytext { color: white; text-align: center; } </style> <script> var words = "The cat sat on the mat"; document.writeln("id='mytext"+ words '); </script> </head> <body> </body> </html>
I am trying to create a slide show using JavaScript. This is what I have so far: HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Slide Show</title> <link rel="stylesheet" href="main.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="slide_show.js"></script> </head> <body> <section> <h1>Fishing Slide Show</h1> <ul id="image_list"> <li><a href="images/casting1.jpg" title="Casting on the Upper Kings"></a></li> <li><a href="images/casting2.jpg" title="Casting on the Lower Kings"></a></li> <li><a href="images/catchrelease.jpg" title="Catch and Release on the Big Horn"></a></li> <li><a href="images/fish.jpg" title="Catching on the South Fork"></a></li> <li><a href="images/lures.jpg" title="The Lures for Catching"></a></li> </ul>...
HTML Canvas: I have given my small html + js mix code below. By this program- I can just draw line, but after drawing any image I want to save the "image " on my desktop. I understand, I have to make a "button" to SAVE it and later if I want to load the picture, then I have to make a button on the webpage to "LOAD". But I am unable to understand the function I should write for...
HTML , Javascript Canvas problem:
could you pleaseeee help me to do these things-
suppose, user draw a picture, then that picture(lines on Canvas)
will be saved as commands, so when the user will refresh the
webpage or when I will execute the code, then when I will press the
"load" button, the last picture which I made will come on the
canvas from localStorage.
<!DOCTYPE html>
<html>
<head>
<script>
var commands = [];
var start = 0;
var c;...
How do i make my html show 10 results per page, and how do i make the books clickable to show results about them? <!DOCTYPE html> <html> <head> <title>Google Books Search</title> <script src="https://code.jquery.com/jquery-2.1.4.min.js"> </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <style> body{ background:lightblue } .wrap{ max-width:400px; margin:auto; margin-top:10px; } .pagination, pagination-last{ float:left; } a{ text-decoration:none; padding:15px 20px; border:1px solid black; border-right:none; background:#f2f2f2; font-size:18px; font-weight:bold; } .pagination-last a{ border-right:1px solid black; } a:hover { background:orange; color;white; } </style> <!-- <script src="js/main.js"></script> --> <script> function B_Search()...
Please advise what is being doing wrong. Requirement. See if you can modify the code of Listings 17.1 and 17.3 to present a message to the user while waiting for an Ajax request to complete. //Code <!DOCTYPE html> <html> <head> <title>Keywords Grabber</title> <script src="myAjaxLib.js"></script> <script> function display(content) { document.getElementById("displaydiv").innerHTML = content; </script> <script> function getXMLHttpRequest() { try { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { return new ActiveXObject("Msxml2.XMLHTTP"); } } catch(e) { return new XMLHttpRequest(); } } function doAjax(url,...
The code below modifies the CSS style on button click. Give the output of the code and modify the code such that background color of title should also be modified . <!DOCTYPE html> <html lang="en"> <head> <title>JavaScript and HTML</title> <meta charset="utf-8"/> <style> h1 { color:blue; background-color:lightGreen; border:12px solid green; padding: 5px; border-radius: 15px; text-align: center; } p, h1 { } } </style> <script> function changeTitleCSSStyle() { var title = document.querySelector("#mainTitle"); title.style.color = 'black'; title.style.border = "5px dashed red"; } </script>...