Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Alejandro Narvaja
PLUS
Alejandro Narvaja
Courses Plus Student 7,340 Points

Why strange reason if I use 'let' instead of 'var' in JS works in all browsers except in the mobile?

On this website I have changed the way to call the variables. I read that 'var' is not used anymore, but instead 'let' is used. I did it, and in browsers it works fine, but on mobile phones it does not. Why does this happen?

The web is: https://alebarbaja.github.io/buscaminas-cssgrid/

Thank you!

6 Answers

Jonathan Mitten
PLUS
Jonathan Mitten
Courses Plus Student 11,197 Points

@alejandronarvaja, Here's the counter working successfully: https://www.dropbox.com/s/4rlm8skgw0qhh9c/minesweeper-seconds-ios.mp4?dl=0

This is on iOS, running Chrome - but if I recall correctly, all iOS browsers are required to use the Safari engine, and should each render the pages the same.

Edit: here's the Safari browser, rendering the same.... : https://www.dropbox.com/s/3a8n2akpkoyec6i/minesweeper-iOS-safari.mov?dl=0

Alejandro Narvaja
Alejandro Narvaja
Courses Plus Student 7,340 Points

Jonathan, you've taken the trouble to try it, upload it to Dropbox and everything is something I did not expect. Millions of thanks, obviously something is failing on my mobile, I will look what it is because apparently it works well.

Thank you very much for your response and obviously thank the others for trying to explain what was happening.

Cheers!

"let" is the more modern method of declaring a variable, as is part of the ES6+ JavaScript, but ES6+ may not be fully supported by the mobile browser that you're testing it on. That would be my first guess, as long as it IS working on the mobile device when using "var". You can usually see 'what works where' by checking it out on "https://caniuse.com/"

Steven Parker
Steven Parker
231,271 Points

According to Can I Use?, the "let" keyword is not supported in any version of Opera Mini, and not in Andriod prior to version 56.

I would not agree "that 'var' is not used anymore", and there are reasons besides browser compatibility that might make "var" still a desirable choice in some programming situations. For examples: "let" will not create a property on the global object, and "let" bindings are not subject to Variable Hoisting.

For more details on the differences, see the MDN pages on both var and let.

Jonathan Mitten
PLUS
Jonathan Mitten
Courses Plus Student 11,197 Points

var and let are both still valid variable keywords, and they will be used differently for different implementation purposes.

To answer your question as to why let works on desktop but not mobile, I don't know which mobile browser you're using, but let should work on it if it's iOS or Android-based. According to caniuse.com, there is support for let on all modern browsers, with the exception of Opera:

https://caniuse.com/#feat=let

Pointing to your github app on my iPhone, I am seeing the same as on desktop Chrome.

If you're still having trouble, post the browser and version you're using to test.

Good luck!

Alejandro Narvaja
PLUS
Alejandro Narvaja
Courses Plus Student 7,340 Points

Thank you people, the truth is that I still have the same problem. I tried it on my mobile with the Safari and Chrome browsers.

@jonathanmitten You say you see it right? The problem I have is that the seconds do not advance in the mobile, however in the desktop it does.

Jonathan Mitten
PLUS
Jonathan Mitten
Courses Plus Student 11,197 Points

In the event you're developing on a Mac, you can follow these instructions, which may help you diagnose your iOS issue. Also, while my iPhone isn't 100% updated, it's running the latest version of iOS, which may make a difference. My iPhone is iPhone 6, running iOS version 11.1.1

https://appletoolbox.com/2014/05/use-web-inspector-debug-mobile-safari/

Alejandro Narvaja
Alejandro Narvaja
Courses Plus Student 7,340 Points

No, I work from Windows, but when I look at the web I do it from the iPhone. I have it updated to the latest version of iOS 10, but it still does not work. Go one to know what will happen, but if at least it works for you it will mean that it is fine.