wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let count: Int = 'info'
let count: String = 'info'
Fix type.
Swift
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
list.forEach(function(item) {{ console.log(item); }})
list.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
if count = 81 then print('value') end
if count == 81 then print('value') end
Use ==.
Lua
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if ($val = 87)
if ($val == 87)
Use ==.
Perl
$item = 22; if ($item = 22) {{}}
$item = 22; if ($item == 22) {{}}
Use ==.
PHP
data(23)
if length(data) >= 23, data(23), end
Check length.
MATLAB
<person><age>value</age><age>11</age></person
<person><age>value</age><age>11</age></person>
Add closing >.
XML
if (b = 12) {{}}
if (b === 12) {{}}
Use === for equality.
JavaScript
const z = 97; z = 17;
let z = 97; z = 17;
Cannot reassign const.
JavaScript
{{'title':35, 'age' 72}}
{{'title':35, 'age':72}}
Colon missing.
Python
for (int i=0; i<99; i++) {{}}
for (int i=0; i<99; i++) {{}}
Correct.
Java
else print('message')
else: print('message')
Colon after else.
Python
int z = 'output';
String z = 'output';
Type mismatch.
Dart
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
let s = String::from("world"); let ref=&s; s.push_str("!");
let mut s = String::from("world"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
for num in range(23) print(num)
for num in range(23): print(num)
Colon after for.
Python
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
let num = 'message'
let num = "message"
Double quotes.
Swift
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
values[71]
if values.indices.contains(71) {{ values[71] }}
Check index.
Swift
["result", 64]
["result", 64]
Correct.
JSON
if (num = 1) {{}}
if (num == 1) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
let b = 42;
let b = 42;
Correct.
JavaScript
jwt.sign({{id:53}}, 'password');
jwt.sign({{id:53}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
if bar = 6
if bar == 6
Use ==.
Go
<person age=6>
<person age="6">
Quote attribute.
XML
const result;
const result = 34;
Initialize const.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
if (b = 18)
if (b == 18)
Use ==.
R
cin >> val;
int val; cin >> val;
Declare variable.
C++
72z = 10
z72 = 10
Variable cannot start with digit.
Python
$list[65] = 5;
if (isset($list[65])) $list[65] = 5;
Check existence.
PHP
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
if a > 76 puts 'test'
if a > 76 puts 'test' end
Add 'end'.
Ruby
print('hello')
print('hello')
Correct.
R
baz
baz()
Add parentheses.
Kotlin
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
if c = 58 {{}}
if c == 58 {{}}
Use ==.
Swift
local b = 8
local b = 8
Correct.
Lua
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let val: i32 = "hello";
let val: &str = "hello";
Type mismatch.
Rust
if ($index = 88) {{}}
if ($index -eq 88) {{}}
Use -eq.
PowerShell
if (temp = 44)
if (temp == 44)
Use ==.
Scala
if index = 33:
if index == 33:
Use == for comparison.
Python
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
while x > 74 x -= 1
while x > 74: x -= 1
Colon missing after while.
Python
if a > 90 print('test')
if a > 90: print('test')
Colon missing after if.
Python
val num: Int = 'output'
val num: String = 'output'
Fix type.
Kotlin
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let mut temp=95; let r1=&mut temp; let r2=&mut temp;
let mut temp=95; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
val c = 'data'
val c = "data"
Double quotes.
Kotlin
index = 51
index=51
No spaces.
Shell
INSERT INTO orders VALUES ('hello',92)
INSERT INTO orders (name, email) VALUES ('hello',92);
Specify columns.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:68}};
Add missing property.
TypeScript
random.sqrt(51)
import random random.sqrt(51)
Import module first.
Python
function bar(): void {{ return 58; }}
function bar(): number {{ return 58; }}
Return type mismatch.
TypeScript
println('value')
println("value")
Double quotes.
Scala
WHERE status = '27'
WHERE status = 27
Don't quote integer.
SQL
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int[] list = new int[78]; list[78] = 5;
int[] list = new int[78]; if (78 < list.length) list[78] = 5;
Check bounds.
Java
class Person {{ int count; }} obj.count=5;
class Person {{ public int count; }} obj.count=5;
Make field public.
Java
let foo = 28; foo += 1;
let mut foo = 28; foo += 1;
Need mut to modify.
Rust
fn process() -> i32 {{ 36 }}
fn process() -> i32 {{ 36 }}
Correct.
Rust
value: test name: data,
value: test name: data
Remove comma.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for (bar in arr)
for (bar of arr)
for...in iterates keys.
JavaScript
// comment
/* comment */
Use /* */.
CSS
yield num
yield num
Correct yield.
Python
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
print 'info'
print('info')
print needs parentheses.
Python
z == '49'
z === 49
Use strict equality.
JavaScript
x := 74
x := 74
Correct.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
[x*x for x in arr if x > 10]
[x*x for x in arr if x > 10]
Correct list comprehension.
Python
test
test()
Add parentheses.
Swift