Skip to content

Instantly share code, notes, and snippets.

@punkrocker178
Last active November 3, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save punkrocker178/586399ea9a1f399295255f1f15c48418 to your computer and use it in GitHub Desktop.
Save punkrocker178/586399ea9a1f399295255f1f15c48418 to your computer and use it in GitHub Desktop.
Generates random number on a fixed table (https://jsbin.com/qubuzoh)
<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>
button{
display:block;
height:60px;
width:100px;
background-color: #000000;
color:white;
border: none;
border-radius: 4px;
margin : 20px;
}
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>")
}
@punkrocker178
Copy link
Author

Web App week 4 exercise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment