[英]Try to solve problem solving using JavaScript
I am facing a problem with this issue我正面临这个问题的问题
this is the question这是问题
This is my solution这是我的解决方案
let whigt = { A: 1, B: 2, C: 3, D: 1, E: 2, F: 3, G: 1, H: 2, I: 3, J: 1, K: 2, L: 3, M: 1, N: 2, O: 3, P: 1, Q: 2, R: 3, S: 4, T: 1, U: 2, V: 3, W: 1, X: 2, Y: 3, Z: 4 } let charwhigt = 0; function presses(phrase) { let arraychar = phrase.toUpperCase().split(""); arraychar.map((el) => { console.log(whigt.el) }) } presses("omar")
I'm trying to link the object key to the letter, but when I print the object's value, it gives me the output NAN我试图将对象键链接到字母,但是当我打印对象的值时,它给了我输出 NAN
What is my mistake did and what is the solution to make the solution right؟؟我的错误是什么以及使解决方案正确的解决方案是什么؟؟
Your code try to search el
into whigt
instead use [el]
will search value of el
您的代码尝试将
el
搜索到whigt
而不是使用[el]
将搜索el
值
let whigt = { A: 1, B: 2, C: 3, D: 1, E: 2, F: 3, G: 1, H: 2, I: 3, J: 1, K: 2, L: 3, M: 1, N: 2, O: 3, P: 1, Q: 2, R: 3, S: 4, T: 1, U: 2, V: 3, W: 1, X: 2, Y: 3, Z: 4 } let charwhigt = 0; function presses(phrase) { let arraychar = phrase.toUpperCase().split(""); arraychar.forEach((el) => { console.log(whigt[el]); }); } presses("omar");
PS: i prefer use forEach
for loop array, see the differente here PS:我更喜欢使用
forEach
for 循环数组, 请参阅此处的不同之处
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.