aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/learn
diff options
context:
space:
mode:
authorKevin CHEN <33132228+KevinZonda@users.noreply.github.com>2021-09-04 20:09:26 +0100
committerGitHub <noreply@github.com>2021-09-05 03:09:26 +0800
commitf3bc00e668d1b986c354b68dec45a7d150d02420 (patch)
tree9bbbc234c42a931824c4e21e4eb71101fb224f1b /files/zh-cn/learn
parent5394433d6158422292de835dbcc55e75821bbe7b (diff)
downloadtranslated-content-f3bc00e668d1b986c354b68dec45a7d150d02420.tar.gz
translated-content-f3bc00e668d1b986c354b68dec45a7d150d02420.tar.bz2
translated-content-f3bc00e668d1b986c354b68dec45a7d150d02420.zip
Update example code in Learn/JavaScript/Building_blocks/Looping_code, zh-CN (#2316)
* sync with en-us page & fix #384 * Update index.html
Diffstat (limited to 'files/zh-cn/learn')
-rw-r--r--files/zh-cn/learn/javascript/building_blocks/looping_code/index.html20
1 files changed, 10 insertions, 10 deletions
diff --git a/files/zh-cn/learn/javascript/building_blocks/looping_code/index.html b/files/zh-cn/learn/javascript/building_blocks/looping_code/index.html
index 3fb1a217da..ab938e9c5b 100644
--- a/files/zh-cn/learn/javascript/building_blocks/looping_code/index.html
+++ b/files/zh-cn/learn/javascript/building_blocks/looping_code/index.html
@@ -312,21 +312,21 @@ para.textContent = info;</pre>
<p>然后是JavaScript:</p>
-<pre class="brush: js">var contacts = ['Chris:2232322', 'Sarah:3453456', 'Bill:7654322', 'Mary:9998769', 'Dianne:9384975'];
-var para = document.querySelector('p');
-var input = document.querySelector('input');
-var btn = document.querySelector('button');
+<pre class="brush: js">const contacts = ['Chris:2232322', 'Sarah:3453456', 'Bill:7654322', 'Mary:9998769', 'Dianne:9384975'];
+const para = document.querySelector('p');
+const input = document.querySelector('input');
+const btn = document.querySelector('button');
-btn.addEventListener('click', function(){
- var searchName = input.value;
+btn.addEventListener('click', function() {
+ let searchName = input.value.toLowerCase();
input.value = '';
input.focus();
- for (var i = 0; i &lt; contacts.length; i++) {
- var splitContact = contacts[i].split(':');
- if (splitContact[0] === searchName) {
+ for (let i = 0; i &lt; contacts.length; i++) {
+ let splitContact = contacts[i].split(':');
+ if (splitContact[0].toLowerCase() === searchName) {
para.textContent = splitContact[0] + '\'s number is ' + splitContact[1] + '.';
break;
- } else {
+ } else if (i === contacts.length - 1) {
para.textContent = 'Contact not found.';
}
}