If you comment out const collection and const source and change
const a = whatIsInAName(collection, source)
to the direct values:
const a = whatIsInAName([{ first: “Romeo”, last: “Montague” }, { first: “Mercutio”, last: null }, { first: “Tybalt”, last: “Capulet” }], { last: “Capulet” } )
then it says:
ReferenceError: source is not defined
Here’s a question.
say i type this:
function a(){
(cursor here already)
}
I want to type the first bracket, and have the text automatically type the 2nd bracket AND put my cursor 1 line above with an indent. Is there anything that does that? Notepad++ doesn’t seem to. Otherwise I have to type left bracket,enter,enter,right bracket,up,tab, for EVERY function/if etc, that’s a horrible workload, python doesn’t multiply your workload by 6 input characters for every for/if.
But most importantly, if you’re good at javascript, can you please tell me why the heck I can’t see a png on my screen with the following code? I can see the png if I use a single canvas (commented out parts) but with an array of canvases, I don’t see a png, I’m stumped. I even put a red fill on there. I see the red fill of a 60x30 area, but no png. I can paste a link to the pngs if you need to test w them. (or just make 18 60wx30h pngs w pixels on transparent background named snake0.png to snake17.png. I see the png on the single canvas just not in the array, so the pngs aren’t the problem
also I purposely made that i variable global, but I still have to feed the i as a parameter to the nameless function or it seems to have weird garbage values. I thought i was global so the nameless function should see it without feeding i as a parameter.
<script>
function main(){
if (paused==false){
ctx.fillStyle='rgb(128,128,128)'
ctx.fillRect(0,0,canvas.width,canvas.height)
ctx2.fillStyle='rgb(255,255,255)'
ctx2.fillRect(0,0,canvas2.width,canvas2.height)
ctx2.drawImage(snakecans[1],0,0) //does not work with array (comment out the opposite line and block below when testing)
//ctx2.drawImage(snakecan,0,0) //does work (no array)
ctx.drawImage(canvas2,0,0,canvas2.width,canvas2.height, 5,5,canvas2.width,canvas2.height)
}
}
canvas=document.getElementById('canvas')
ctx=canvas.getContext('2d')
canvas2=document.createElement('canvas')
canvas2.width=540
canvas2.height=540
ctx2=canvas2.getContext('2d')
//does not work (comment out opposite block and line above when testing)
//can't see any png on screen
//i have 18 pngs. i want to put them in 18 'canvases' (so i guess i need 18 contexts too)
snakecans=[]
snakectxs=[]
var i=0
for(i=0;i<18;i++){
snakecans.push(document.createElement('canvas'))
snakecans[i].width=60
snakecans[i].height=30
snakectxs.push(snakecans[i].getContext('2d'))
im=new Image()
im.src='snake'+String(i)+'.png'
im.onload=function(i,snakectxs){ //you apparently need this onload or the png wont load in time
console.log(i)
snakectxs[i].fillStyle='rgb(255,0,0)'
snakectxs[i].fillRect(0,0,snakecans[i].width,snakecans[i].height)
snakectxs[i].drawImage(im,0,0)
}(i,snakectxs) //says 'snakectxs[i] is undefined' unless I put that stuff in parentheses
}
//does work
//can see png on screen
/*
snakecan=document.createElement('canvas')
snakecan.width=60
snakecan.height=30
snakectx=snakecan.getContext('2d')
im=new Image()
im.src='snake'+String(3)+'.png'
im.onload=function(){
snakectx.drawImage(im,0,0)
}
*/
paused=false
setInterval(main, 1000/60)
</script>