Last active
November 3, 2020 03:15
-
-
Save punkrocker178/586399ea9a1f399295255f1f15c48418 to your computer and use it in GitHub Desktop.
Generates random number on a fixed table (https://jsbin.com/qubuzoh)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
button{ | |
display:block; | |
height:60px; | |
width:100px; | |
background-color: #000000; | |
color:white; | |
border: none; | |
border-radius: 4px; | |
margin : 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="txtBox" | |
name="input" placeholder="Nhap thu gi do"> | |
<br> | |
<button onclick="check()">Check me</button> | |
<button onclick="createTable()">Create me</button> | |
</form> | |
<script id="jsbin-javascript"> | |
function check(){ | |
var x = document.getElementById("txtBox").value; | |
x = parseInt(x); | |
alert(isPrime(x)); | |
} | |
function isPrime(x){ | |
var count=0; | |
for(i =2;i<x/2;i++){ | |
if(x%i==0){ | |
count++; | |
} | |
} | |
if(count==0){ | |
return x; | |
} | |
return -1; | |
} | |
function createTable(){ | |
var str = "<table border=1><tr>" | |
for(i = 1;i<=10;i++){ | |
for(j =1;j<=10;j++){ | |
str+= "<td>"+Math.floor((Math.random()*9)+1) +"</td>"; | |
} | |
str+="</tr>"; | |
} | |
console.log(str); | |
document.write(str+"</table>") | |
} | |
</script> | |
<script id="jsbin-source-html" type="text/html"><html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="txtBox" | |
name="input" placeholder="Nhap thu gi do"> | |
<br> | |
<button onclick="check()">Check me</button> | |
<button onclick="createTable()">Create me</button> | |
</form> | |
</body> | |
</html> | |
</script> | |
<script id="jsbin-source-css" type="text/css">button{ | |
display:block; | |
height:60px; | |
width:100px; | |
background-color: #000000; | |
color:white; | |
border: none; | |
border-radius: 4px; | |
margin : 20px; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function check(){ | |
var x = document.getElementById("txtBox").value; | |
x = parseInt(x); | |
alert(isPrime(x)); | |
} | |
function isPrime(x){ | |
var count=0; | |
for(i =2;i<x/2;i++){ | |
if(x%i==0){ | |
count++; | |
} | |
} | |
if(count==0){ | |
return x; | |
} | |
return -1; | |
} | |
function createTable(){ | |
var str = "<table border=1><tr>" | |
for(i = 1;i<=10;i++){ | |
for(j =1;j<=10;j++){ | |
str+= "<td>"+Math.floor((Math.random()*9)+1) +"</td>"; | |
} | |
str+="</tr>"; | |
} | |
console.log(str); | |
document.write(str+"</table>") | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
button{ | |
display:block; | |
height:60px; | |
width:100px; | |
background-color: #000000; | |
color:white; | |
border: none; | |
border-radius: 4px; | |
margin : 20px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check(){ | |
var x = document.getElementById("txtBox").value; | |
x = parseInt(x); | |
alert(isPrime(x)); | |
} | |
function isPrime(x){ | |
var count=0; | |
for(i =2;i<x/2;i++){ | |
if(x%i==0){ | |
count++; | |
} | |
} | |
if(count==0){ | |
return x; | |
} | |
return -1; | |
} | |
function createTable(){ | |
var str = "<table border=1><tr>" | |
for(i = 1;i<=10;i++){ | |
for(j =1;j<=10;j++){ | |
str+= "<td>"+Math.floor((Math.random()*9)+1) +"</td>"; | |
} | |
str+="</tr>"; | |
} | |
console.log(str); | |
document.write(str+"</table>") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Web App week 4 exercise