-4

I am new to programming and I have a problem for one of my homework and I would like someone who has experience with Javascript or anyone with knowledge of programming to help me to solve this problem please.

I would like to make my function section to return 'true' only if a "filename" ends either in '.jpg' or '.jpeg. Here is the code that I have:

"use strict";

function isWebImageFriendly(filename) {
  return true;
}

I have lots of photos ends with .jpg and.jpeg on my Javascript but I don't know how to write a code so that it only selects the .jpg or .jpeg type of files that I needed.

I was thinking should I write like this:

"use strict";

function isWebImageFriendly(filename) {
<form onsubmit="return isWebImageFriendly(filename);"></form>      
return true;
}
2

1 Answer 1

1

You can use regex:

function isWebImageFriendly(filename) {
  return filename.match(/\.jpe?g$/)
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for trying to help me out. I tried to use that function that you suggested to me but when i reload my page there are nothing showing my on webpage, is it because I need insert the function under a variable? I have a variable called var photo_details = [ lists of photos....] should I do it like this function isWebImageFriendly(photo_details) {return photo_details.match (/\.jpg?g$/)}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.