Skip to content

饿了么暑期笔试

选择题

1.js
js
var name = 117;
const obj = {
  name: "John",
  func: function () {
    console.log(this.name);
  },
};

(obj.name === "John" ? obj.func : "")();
2.txt
txt
document.body.style.["background-color"] = '#fff';
document.body.style.setProperty('background-color', '#fff');
document.body.style = 'background-color': '#fff';
document.body.style.fontSize = '30px'
3.js
js
var name = "tom";
function getMethod() {
  var result = () => name;
  var name = "Jerry";
  return result;
}
var getName = getMethod();
var name1 = getName();
console.log(name1);

编程题

4.js
js
function getSum(str) {
  let result = "";
  for (const s of str) {
    if (/[a-z]$/.test(s)) {
      result += s.toUpperCase();
    } else {
      result += s.toLowerCase();
    }
  }
  return result
    .split("")
    .reduce(
      (acc, cur, index) => (index % 2 === 0 ? acc + cur.charCodeAt() : acc),
      0,
    );
}
console.log(getSum("HeLlo"));