PIEBALDconsult wrote:
Its a cool website but the JavaScript one was pretty disappointing, its badly written, then encrypted with an escape sequence to hide the actual code.
PIEBALDconsult wrote:
Its a cool website but the JavaScript one was pretty disappointing, its badly written, then encrypted with an escape sequence to hide the actual code.
Here's the one I made. 194 characters long. This is my first time code golfing, but I think i'm getting the hang of it. :suss:
for(var $=b=c=d='',_=99,a=' on the wall.';b=' bottle'+(~(_-2)?'s':d)+' of beer',_>~0;c=_--&&'\n\n') 99-_&&($+='.\nTake one down and pass it around, '+(_||'no more')+b+a),$+=_?c+_+b+a+', '+_+b:d;
console.log($);
Course I can do it, I just want to see some new, clever approaches. What, does nobody code for fun anymore? Here, i'll post mine.
Here:
<html>
<body>
<input id='input' type='file' onchange='newImage()'/>
Preview:
<button onclick='downloadImage()'>Download</button>
<script>
var input=document.getElementById('input'); //the <input> element
var image=document.getElementById('img'); //the element
function newImage(){
if(!input.files||input.value=='') return; //if there is no file then exit function
var file=input.files[0]; //get the file
if(!file.type.match('image.*')){ //if file is not an image
input.value=''; //clear input
alert('Images only!');
return; //exit function
}
var reader=new FileReader(); //now we read the image
reader.readAsDataURL(file); //convert image into a string
reader.onload=function(f){ //once the image string is received...
image.src=f.target.result; //send the image string to the image element
}
}
function downloadImage(){
if(!image.src){
alert('There is nothing to download!');
return; //exit function if there is no image
}
var a=document.createElement('a');
a.setAttribute('href',image.src);
a.setAttribute('download','image.png');
a.click();
}
</script>
</body>
</html>
Your welcome :-\
Your right, my bad
In JavaScript I need the shortest possible code to generate the 99 bottles of beer on the wall song lyrics into a string (using "\n" as the line separator). The problem is making it grammatically correct while still keeping the code compact. For a refresher: 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall. 97 bottles of beer on the wall, 97 bottles of beer. Take one down and pass it around, 96 bottles of beer on the wall. ... 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall. I'm searching for the cleverest, most compact approach. Any ideas?
There's 2 approaches you can take
window.scrollTo(0,0);
DOM_ELEMENT.scrollIntoView(false);
Here's a little example :)
<html>
<body onload='createAnnoyingStuff()' onscroll='preventScroll()' style='text-align:center'/>
<script>
function createAnnoyingStuff(){
for(var i=0;i<100;i++){
document.body.appendChild(document.createTextNode('Pete and Repeat were on a boat. Pete fell out, who was left?'));
document.body.appendChild(document.createElement('br'));
}
document.body.appendChild(document.createTextNode('The End'));
}
function preventScroll(){
window.scrollTo(0,0);
}
</script>
</html>
There's no way to get to "The End" which is at the bottom of the body Does this help at all?
Here:
<html>
<body>
<input id='input' type='file' onchange='newImage()'/>
Preview:
<button onclick='downloadImage()'>Download</button>
<script>
var input=document.getElementById('input'); //the <input> element
var image=document.getElementById('img'); //the element
function newImage(){
if(!input.files||input.value=='') return; //if there is no file then exit function
var file=input.files[0]; //get the file
if(!file.type.match('image.*')){ //if file is not an image
input.value=''; //clear input
alert('Images only!');
return; //exit function
}
var reader=new FileReader(); //now we read the image
reader.readAsDataURL(file); //convert image into a string
reader.onload=function(f){ //once the image string is received...
image.src=f.target.result; //send the image string to the image element
}
}
function downloadImage(){
if(!image.src){
alert('There is nothing to download!');
return; //exit function if there is no image
}
var a=document.createElement('a');
a.setAttribute('href',image.src);
a.setAttribute('download','image.png');
a.click();
}
</script>
</body>
</html>
Your welcome :-\
You are thinking of a database file (.db), which you create in Microsoft Access (or any other database editing software), then you host that file on the internet along with all your other files. Then whenever you want to create a new user, you can add another row into the database table.
I've recently gotten into Javascript, and let me tell you, I love it so much more than VB.NET (which was my favorite language too). I say just move on, I think VB.NET was designed to get people into programming, but once programmers become pro at VB.NET, their supposed to move on to better, faster programming languages which have more real-world applications. :)
I dont know if this will help, but here's a few snippets I made to convert between bases in Javascript
var characters='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
To convert decimal to base 36:
var decimal=21828139225;
var a=decimal,code='';while(a!=0) var code=characters.charAt(a%characters.length)+code,a=Math.floor(a/characters.length);
alert(code);
To convert base 36 to decimal:
var code='A0ZWS0P';
for(var i=decimal=0,len=code.length;i
A while back, I took this whole base conversion thing way too far, and made the ultimate base conversion tool which can be found at https://www.dropbox.com/s/qmize4qx4hf6lrn/Number%20System%20Conversion%20and%20Encryption.html?dl=0
If you're ever in doubt, you can always resort back to the conversion chart, it never lies!
Happy Coding!