Function variables problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Function variables problem

Iam trying to teleport my character 1000px to the right. function keypress(loc,add){ if(add == false){ a = '++'; } else { a = '--'; } character = document.getElementById('character').style; character.loc = '1000px'; console.log(loc); }

17th Apr 2018, 12:35 PM
Arne Van Kerckvoorde
Arne Van Kerckvoorde - avatar
2 Answers
+ 2
Hi Skizzles There is no "loc" attribute in DOM Elements. So assigning a value to it wont achieve anything. You can only really set the top and left attributes in CSS for your character. Something like this. var character = document.getElementById('character); = '1000px'; = '100px'; Dont forget to make the item absolute/fixed positioned
17th Apr 2018, 3:26 PM
Mike Choy
Mike Choy - avatar
24th Apr 2018, 3:31 AM
Md Eyasin Ali
Md Eyasin Ali - avatar