+ 16

[solved] How do I convert a text to an emoji?

I wanted to make a program that collects a property from an object and checks if that property matches a character or a word in a given sentence, if true then the program replaces that property with it's corresponding value. e.g obj = { ":)" : "🙂", ":(" : "☹️" } str = "hello friend :)" I want my output to be hello friend 🙂 I have tried solving this but my code returns no output. please help. my code [produces no output] https://code.sololearn.com/WRkJLPpEozU4/?ref=app

10th Jan 2021, 4:06 AM
Stonny
Stonny - avatar
22 Respuestas
+ 21
Stonny emoji is an object not array so you have to do if(j == words[i]) edited: if (j == words[i]) { words[i] = emoji[j]; } https://code.sololearn.com/WOK0vpTLdmbB/?ref=app
10th Jan 2021, 4:25 AM
A͢J
A͢J - avatar
+ 6
Hi Stonny , 🙂 Hope this will help 🐾 https://code.sololearn.com/WFMM50G070Hb/?ref=app
10th Jan 2021, 4:38 AM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
+ 6
I also don't know about thanks for questioning I got my Answer 💓
10th Jan 2021, 4:19 PM
SUJAN
SUJAN - avatar
+ 3
Ipang I don't really understand the code. I tried replacing the 0 and 1 with emojis but got confused in line 21
10th Jan 2021, 4:33 AM
Stonny
Stonny - avatar
+ 3
Stonny You are joining the word inside the condition so when condition will match then it will be append in words otherwise not that's why you got only :)
10th Jan 2021, 4:36 AM
A͢J
A͢J - avatar
+ 3
I Am AJ ! Thanks your solution, it works. It is what I want. [solved]https://code.sololearn.com/WOK0vpTLdmbB/?ref=app
10th Jan 2021, 4:38 AM
Stonny
Stonny - avatar
+ 3
Stonny Arnav Kumar [📕Schools📚] There are many ways to achieve this. You can also do like this: for(i in words) { if (emoji [words[i]]) //it will return true if exist words[i] = emoji [words[i]]; } words = words.join(" ")
10th Jan 2021, 4:56 AM
A͢J
A͢J - avatar
+ 3
Another way of using replaceAll method. Get all the key elements into an array using Object.keys method, then iterate replaceAll method with respected key and value. You only need this: Object.keys(emoji).forEach(key => words = words.replaceAll(key, emoji[key])); https://code.sololearn.com/WOkgBCC1bmWq/?ref=app
10th Jan 2021, 9:38 AM
Calviղ
Calviղ - avatar
+ 2
I wrote this to answer a friend just the other day. If you comment line 47 and add the emojis to the <sym> object, I think you can have just what you want. https://code.sololearn.com/WV2nFIAbBtsf/?ref=app
10th Jan 2021, 4:24 AM
Ipang
+ 2
Stonny Check my edited code again
10th Jan 2021, 4:30 AM
A͢J
A͢J - avatar
+ 2
Stonny You missed one more thing in your code for (j in emoji) //here j but you wrote emoji [i] there should be emoji [j]
10th Jan 2021, 4:39 AM
A͢J
A͢J - avatar
10th Jan 2021, 4:44 AM
Arnav Kumar [Less/Not Active]
Arnav Kumar [Less/Not Active] - avatar
+ 2
Thanks so much Ipang it really helps :)
10th Jan 2021, 4:44 AM
Stonny
Stonny - avatar
+ 2
Arnav Kumar [📕Schools📚] I really appreciate your own version. I'm learning so much from this exercise :) thanks so much
10th Jan 2021, 4:46 AM
Stonny
Stonny - avatar
+ 2
Narayan Tirvir I suggest you post your question direct on your Q&A page so everyone can see it.
11th Jan 2021, 10:35 AM
Stonny
Stonny - avatar
+ 2
Narayan Tirvir You are asking at wrong place.
11th Jan 2021, 2:12 PM
A͢J
A͢J - avatar
+ 1
I Am AJ ! I just did that now and got ':)' as the only output
10th Jan 2021, 4:28 AM
Stonny
Stonny - avatar
+ 1
Stonny The code was meant to replace characters in each string in an array <maps>. A bit of adjustment will get you right.
10th Jan 2021, 4:38 AM
Ipang
+ 1
Thanks so much P∆WAN M∆URY∆ It works perfect 🤩
10th Jan 2021, 4:42 AM
Stonny
Stonny - avatar
10th Jan 2021, 4:56 PM
Ashish Vishwakarma
Ashish Vishwakarma - avatar